I would like to do something like:
<%# 开发者_如何学运维if((bool)Eval("IsDisabled")){ %><span>Disabled</span><% }
else { %><span>Active</span><% } %>
but I don't think its possible. There is a way to create method in codebehind which returns appropriate string and call it, but thats not an option.
You can use placeholders to hold the two versions of your markup and then use the Visible property to show the relevant one. Something like this... Note the use of ! before the call to IsDisabled in the second Visible property.
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# IsDisabled((bool) Eval("IsDisabled")) %>'>
<span>Disabled</span>
</asp:PlaceHolder>
<asp:PlaceHolder ID="PlaceHolder2" runat="server" Visible='<%# !IsDisabled((bool) Eval("IsDisabled")) %>'>
<span>Active</span>
</asp:PlaceHolder>
The code behind IsDisabled method looks like this...
public bool IsDisabled (bool isDisabled)
{
return isDisabled;
}
Its not possible to use # eval in if statement,
You have some options to solve that:
- You can put the condition of the if in a previous line then check on this variable in the if
example: in code behind:
protected bool isDisabled;
in aspx:
<%# isDisabled=(bool)Eval("IsDisabled") %>
<% if(isDisabled) %>
- Other way is to call a code behind method which return bool and check on it in the if.
精彩评论