【问题标题】:Dynamically Add Link Button To ASP Grid View将链接按钮动态添加到 ASP 网格视图
【发布时间】:2018-01-10 23:16:29
【问题描述】:

我正在尝试在我的 C# 语法中使用以下代码将链接按钮添加到 asp:gridview。输出窗口显示添加的文本标签,因此代码似乎按照应有的方式进行了迭代。但是,当页面加载时,没有链接按钮。

我应该如何设置才能加载链接按钮?

    protected void gvRR_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    string[] rrar= new string[] { "Value Basis For Customer Support:" };
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        foreach (TableCell row in e.Row.Cells)
        {
            if (rrar.Any(x => x == e.Row.Cells[1].Text))
            {
                LinkButton lb = new LinkButton();
                lb.ID = "lbcoded";
                lb.Text = e.Row.Cells[1].Text;
                e.Row.Cells[1].Controls.Add(lb);
                System.Diagnostics.Debug.Print("Label Added");
            }
        }
    }
}

【问题讨论】:

    标签: c# asp.net gridview webforms


    【解决方案1】:

    您将尝试在 ItemTemplate 中更早地添加 LinkBut​​ton 而不是动态添加,这会使您的生活更轻松。 在 RowDataBound 中找到 LinkBut​​ton 并根据条件显示/边。

    或者,您可以尝试在 gvRR_RowCreated 事件中添加 LinkBut​​ton 吗?

    protected void gvRR_RowCreated(object sender, GridViewRowEventArgs e)
    {
       //Put your code of add link buttone
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多