急! ! ! !急! ! ! !急! ! ! !aspx页面中的判断问题!
怎么在aspx页面中加判断条件啊,我在表里设置一字段,当为一时HyperLink为红色显示,否则blue,怎么写呢?这两种写法都不成啊:
<asp:HyperLink ID= "Hyperlink1 " ForeColor= <%# DataBinder.Eval(Container.DataItem, "flag ")== "1 "? "red ": "BLUE "%> Text= ' <%# chkStrLen(DataBinder.Eval(Container.DataItem, "title ").ToString(),20)%> ' Target=_blank runat=server>
</asp:HyperLink>
------解决方案--------------------Hyperlink1.ForeColor = flag == 1 ? System.Drawing.Color.Red : System.Drawing.Color.Blue;
------解决方案-------------------- <asp:HyperLink ID= "HyperLink2 " runat= "server " ForeColor= ' <%#(DataBinder.Eval(Container.DataItem, "flag ").ToString() == "1 ") ? System.Drawing.Color.Red : System.Drawing.Color.Blue%> '> 编辑 </asp:HyperLink>
------解决方案--------------------在后台写个方法:
public string changColor(string test)
{
if(test== "1 ")
{
return "red ";
}
else
{
return "blue ";
}
}
前台调用:
<asp:HyperLink ID= "Hyperlink1 " ForeColor= <%# changColor(Convert.ToString(DataBinder.Eval(Container.DataItem, "flag ")))%> ...