Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何禁用数据列表中的链接按钮?_C#_Javascript_Asp.net - Fatal编程技术网

C# 如何禁用数据列表中的链接按钮?

C# 如何禁用数据列表中的链接按钮?,c#,javascript,asp.net,C#,Javascript,Asp.net,我使用上面的方法在点击一次链接按钮后禁用链接按钮,但我面临的问题是,当我点击其他链接按钮(在其他行中)时,先前禁用的链接按钮会被启用 我想要的是禁用链接按钮,直到我无法从任何其他事件或方法中启用它。我建议您使用数据列表的项数据绑定事件 protected void lnk_Add_Click(object sender, DataListCommandEventArgs e) { Label id = (Label)e.Item.FindControl("lbl_PID"); L

我使用上面的方法在点击一次链接按钮后禁用链接按钮,但我面临的问题是,当我点击其他链接按钮(在其他行中)时,先前禁用的链接按钮会被启用


我想要的是禁用链接按钮,直到我无法从任何其他事件或方法中启用它。

我建议您使用
数据列表的
项数据绑定
事件

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;

}

基于此链接:

只要在
页面加载事件中(!IsPostBack)
将网格绑定到
中即可?听起来好像每次回发时都要重新绑定列表。是的,我认为这是唯一的问题,我在页面加载时再次绑定了数据列表。我刚刚使用了If(!IsPostBack)属性,我的代码工作正常。非常感谢@michealsem在每个后处理事件上绑定数据列表这样的问题,请仅在If(!Page.IsPostBack)块上限制它。。
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;

         }

}