数据绑定时gridview中的按钮是否可见?在Asp.net?

时间:2012-04-11 05:08:27

标签: asp.net

在Web应用程序中,我将在绑定数据时禁用该按钮,这样可能会出现错误吗?

 <asp:Button ID ="btn" runat ="server"  CommandArgument='<%# Eval("id").ToString() == "1"? visble false: Visible true %>' />

3 个答案:

答案 0 :(得分:2)

在DataGrid RowDataBound事件

中执行此操作

答案 1 :(得分:2)

要么在数据绑定事件中执行此操作,要么像这样执行...

<asp:Button ID ="btn" runat ="server" Visible='<%# Eval("id").ToString() == "1"? "false" : "true" %>' />

答案 2 :(得分:2)

试试这个:

 <asp:Button ID="Button1" runat="server" Text="Button" Visible='<%#getVisibility()%>' OnClick="btn_Click" />

代码背后:

public Boolean getVisibility()
{
   Boolean b = false;
   //get the boolean value based on your field condition
   b = Convert.ToBoolean(Eval("FieldValue").ToString() != "MatchCondition" ? "true" :     "false");
   return b;
}