Asp.net 要基于Gridview字段中的值启用图像按钮吗
在Gridview中,我使用希望根据字段中的值启用的图像按钮。我的部分代码是Asp.net 要基于Gridview字段中的值启用图像按钮吗,asp.net,c#-4.0,Asp.net,C# 4.0,在Gridview中,我使用希望根据字段中的值启用的图像按钮。我的部分代码是 <asp:ImageButton ID="btn_delete" **Enabled='<%# Eval("fld_status").ToString()=="1" ? "False" : "True" %>**' runat="server" ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you del
<asp:ImageButton ID="btn_delete" **Enabled='<%# Eval("fld_status").ToString()=="1" ? "False" : "True" %>**' runat="server" ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_id") %>' />
通过
RowDataBound
(我更喜欢):
从aspx:
<asp:ImageButton ID="btn_delete" runat="server"
Enabled='<%# ((int)Eval("fld_status") !=1) ? true : false %>'
ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_id") %>'
/>
如果fld_status=1表示,我想为图像按钮设置Enable=“False”。您是否尝试在gridview的DataItemBounded事件中执行此操作?第二个是否有效aspx:CS0019:Operator'!='中的服务器标记格式不正确不能应用于'object'和'int'类型的操作数@codingbiz:Corrected,这就是为什么我总是使用RowDataBound
@bharathi。您应该使用codebehind中的RowDataBound-它是干净的,但如果在aspx中工作,则很容易更改。尽管如此,显示错误的指定强制转换仍然无效。
<asp:ImageButton ID="btn_delete" runat="server"
Enabled='<%# ((int)Eval("fld_status") !=1) ? true : false %>'
ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_id") %>'
/>