GridView,DetailsView如何在ItemTemple里做判断
<asp:TemplateField HeaderText="绑定">
<ItemTemplate>
<%
if(true)----这里应该怎么写
{%>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("device") %>'></asp:Label>
<%
}
else{ %>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("device") %>'></asp:Label>
<%}%>
</ItemTemplate>
</asp:TemplateField>
我不能写if(Eval())或者if(Bind())
请问,if里面应该怎么写 --------------------编程问答-------------------- 把绑定的字段传到后台去判断不行吗 --------------------编程问答--------------------
解决办法当然很多,这算是一种思路 --------------------编程问答-------------------- gridview 有个RowDataBound事件 这个是在绑定数据中可以判断的
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if(true){ //干嘛? } else{ //干嘛 } } }
--------------------编程问答-------------------- 上面可能不清楚再来一次:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)--------------------编程问答-------------------- 用二元式
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (true)
{
//做什么
}
else
{
//做什么
}
}
}
<%# Eval("isCheck").ToString()=="True"?"通过":"未通过" %> --------------------编程问答-------------------- 三元运算符,楼上已经给出答案了。
补充:.NET技术 , ASP.NET