如何启用数据列表中的禁用按钮

发布于 2024-11-06 08:53:07 字数 679 浏览 3 评论 0原文

我有一个数据列表,其中包含一些带有 2 个按钮的数据绑定字段。我想根据每行的列(状态)值启用禁用按钮,因此例如,如果状态的值为 0 ,则应禁用删除按钮,而当状态值为 1 时,应类似地启用添加按钮,反之亦然..

protected void dlEditCaravans_ItemDataBound(object sender, DataListItemEventArgs e)
{
    Button addtoFeauture = e.Item.FindControl("btnAddToFeature") as Button;
    Button removetoFeauture = e.Item.FindControl("btnRemoveFeature") as Button;
    int id = Convert.ToInt32(dlEditCaravans.DataKeys[e.Item.ItemIndex]);
    int check = caravans.GetfeautureValue(id);

    if (check == 0)
    {
        addtoFeauture.Enabled = true;

    }

    else
    {
        removetoFeauture.Enabled = true;

    }

  }

我尝试过类似上面的方法,但它给出了对象引用未设置为实例错误。

I have got a datalist with some databound fields with 2 buttons. I want to enable disable button depending on the column(state) value of each row, so for instance if the value of state is 0 , the remove button should be disable and add button should be enabled similarly when the value of state is 1 , vice versa..

protected void dlEditCaravans_ItemDataBound(object sender, DataListItemEventArgs e)
{
    Button addtoFeauture = e.Item.FindControl("btnAddToFeature") as Button;
    Button removetoFeauture = e.Item.FindControl("btnRemoveFeature") as Button;
    int id = Convert.ToInt32(dlEditCaravans.DataKeys[e.Item.ItemIndex]);
    int check = caravans.GetfeautureValue(id);

    if (check == 0)
    {
        addtoFeauture.Enabled = true;

    }

    else
    {
        removetoFeauture.Enabled = true;

    }

  }

I have tried something like above but it gives object reference not set to an instance error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情感失落者 2024-11-13 08:53:07

您需要使用Datalist的ItemDatabound事件

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
 if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {
        DataRow dr = ((DataRowView)e.Item.DataItem).Row;
        if (Convert.ToBoolean(dr["StateColumnName"])
        {
          ((Button)e.Item.FindControl("Button1")).Enable = True;
        }
    }
}

You need to use ItemDatabound event of Datalist

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
 if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {
        DataRow dr = ((DataRowView)e.Item.DataItem).Row;
        if (Convert.ToBoolean(dr["StateColumnName"])
        {
          ((Button)e.Item.FindControl("Button1")).Enable = True;
        }
    }
}
戈亓 2024-11-13 08:53:07
  void DataListProduct_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
     {
         if (e.Item.ItemType == ListItemType.Item ||
             e.Item.ItemType == ListItemType.AlternatingItem)
         {

             Button BT = e.Item.FindControl(“ButtonID“) as Button;
             BT.Enable = True or false depends upon your condition
         }

     }
  void DataListProduct_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
     {
         if (e.Item.ItemType == ListItemType.Item ||
             e.Item.ItemType == ListItemType.AlternatingItem)
         {

             Button BT = e.Item.FindControl(“ButtonID“) as Button;
             BT.Enable = True or false depends upon your condition
         }

     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文