[英]How to disable a link button in a Datalist?
protected void lnk_Add_Click(object sender, DataListCommandEventArgs e)
{
Label id = (Label)e.Item.FindControl("lbl_PID");
Label lbl_P_Name = (Label)e.Item.FindControl("lbl_PN");
Image P_Image = (Image)e.Item.FindControl("Img");
LinkButton lnkbtn = (LinkButton)e.Item.FindControl("lnk_Add");
lnkbtn.Enabled = false;
}
I am using above method for Disabling a link button after it has been clicked once but the problem I am facing is that when ever I click on other link button(In other Row) the previous link button which was disable gets enable. 我正在使用上述方法来单击一次链接按钮之后将其禁用,但是我面临的问题是,当我单击其他链接按钮(在另一行中)时,以前被禁用的链接按钮会被启用。
What I want is to disable a linkbutton until I don't enable it from any other event or method. 我想要的是禁用一个链接按钮,直到我从任何其他事件或方法都不启用它为止。
I suggest you to use ItemDataBound
event of your Datalist
我建议你使用
ItemDataBound
您的事件Datalist
void Item_Bound(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
var lnkbtn = (LinkButton)e.Item.FindControl("lnk_Add");
lnkbtn.Enabled = false;
}
}
Based on this link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx 基于此链接: http : //msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx
只需在page_load
事件中将网格绑定到If(!IsPostBack)
中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.