Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 访问正则内联表达式中的数据绑定变量_C#_Asp.net - Fatal编程技术网

C# 访问正则内联表达式中的数据绑定变量

C# 访问正则内联表达式中的数据绑定变量,c#,asp.net,C#,Asp.net,我试图访问正则C#内联表达式中的数据绑定变量 我希望有某种方法可以使用Eval()命令访问它,但不能在常规内联代码块中使用它。(我的意思是,标记) 注意:下面的内联代码不完整,我预先设置了布尔值(IsCommented) <% if (IsCommented) Response.Write("<a href='#' onclick='Comment(" + Eval("commentid") + "', $(this)); return false;' cla

我试图访问正则C#内联表达式中的数据绑定变量

我希望有某种方法可以使用
Eval()
命令访问它,但不能在常规内联代码块中使用它。(我的意思是,
标记)

注意:下面的内联代码不完整,我预先设置了布尔值(IsCommented)

<%
    if (IsCommented)
        Response.Write("<a href='#' onclick='Comment(" + Eval("commentid") + "', $(this)); return false;' class='btn btn-info'>Comment</a>");
    else
        Response.Write("<a href='#' onclick='Comment(" + Eval("commentid") + "', $(this)); return false;' class='btn btn-inverse'>Commented!</a>");
%>

这有可能吗


(请注意,我的所有内容都包含在
列表视图中)

我没有正确理解您的问题

但是你是在寻找这样的东西,还是这能解决你的问题

<%if (IsCommented) {%>
        <a href='#' onclick='Comment('<%#Eval("commentid")%>', $(this)); return false;' class='btn btn-info'>Comment</a>;
    <%}else{%>
        <a href='#' onclick='Comment('<%#Eval("commentid")%>', $(this)); return false;' class='btn btn-inverse'>Commented!</a>";
<%}%>

;
";

谢谢!这很有帮助,尽管我最终重新编写了程序,以不同的方式解决问题。你能解释一下内联表达式中变量的生存期及其作用域吗?在看到这一点之前,我假设如果在标记外声明一次内变量,我将无法访问该变量,尽管显然不是这样的。很高兴我能帮上忙!这篇文章可以帮助你理解