要根据GridView的字段中的值,以使图像按钮 [英] Want to enable image button based on the value in the Gridview Field
本文介绍了要根据GridView的字段中的值,以使图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在GridView的我使用图像按钮希望基于字段中的值来启用。我偏code是..
< ASP:ImageButton的ID =btn_delete**启用='<%#的eval(fld_status)的ToString()==1? 假:;'(?重要提示:您删除此项目)的CommandName =删除CommandArgument =真%&GT **收益确认'=服务器工具提示=删除的OnClientClick =' <%#绑定(fld_id)%>' />
解决方案
通过的RowDataBound
(我preFER):
保护无效gridview1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView的行=(DataRowView的)e.Row.DataItem;
INT状态=(int)的行[fld_status];
按钮btn_delete =(按钮)e.Row.FindControl(btn_delete);
btn_delete.Enabled =状态= 1!;
}
}
从ASPX:
< ASP:ImageButton的ID =btn_delete=服务器
启用='<%#((INT)的eval(fld_status)= 1!)?真:假%GT;'
工具提示=删除的OnClientClick =返回确认(重要提示:你删除此项目')的CommandName =删除CommandArgument ='<%#绑定(fld_id)%>'
/>
In Gridview i am using image button that Want to enable based on the value in the Field. My Partial Code is ..
<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") %>' />
解决方案
via RowDataBound
(which i prefer):
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView row = (DataRowView)e.Row.DataItem;
int status = (int)row["fld_status"];
Button btn_delete = (Button) e.Row.FindControl("btn_delete");
btn_delete.Enabled = status != 1;
}
}
from 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") %>'
/>
这篇关于要根据GridView的字段中的值,以使图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文