Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a databound variable in regular inline expression

Tags:

c#

asp.net

I'm trying to access a databound variable within a regular C# inline expression.

I was hoping there was some way I could access it using the Eval() command, but you cannot use it inside a regular inline code block. (What I mean by that, is the <% %> tag).

NOTE: The below inline code is not complete, I set the boolean (IsCommented) beforehand.

<%
    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>");
%>

Is this at all possible?

(Note that I have this all contained within a ListView)

like image 385
Austin Zurfluh Avatar asked Nov 25 '25 18:11

Austin Zurfluh


1 Answers

I am not getting your question properly,

But are you looking for something like this or will this solve your problem

<%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>";
<%}%>
like image 67
Pawan Nogariya Avatar answered Nov 27 '25 07:11

Pawan Nogariya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!