【问题标题】:How to add new column to asp.net gridview where columns are autogenerated?如何将新列添加到自动生成列的asp.net gridview?
【发布时间】:2010-07-20 14:02:20
【问题描述】:

如何将新的超链接列添加到自动生成列的 asp.net gridview?列未在 gridview 中预定义。

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    只需将您的列定义添加到网格视图的部分。您的自动生成的列应显示在此列的左侧。

    <asp:gridview AutoGenerateColumns="true" ... >
        <columns>
            <asp:hyperlink ... />
        </columns>
    </asp:gridview>
    

    【讨论】:

    • 谢谢。这将是 HyperLinkField 而不是常规的超链接控件会出错。
    【解决方案2】:

    我发现自动生成的列显示在右侧。如果您希望它们位于左侧,则必须向 RowCreated 事件添加代码,该事件会删除并重新添加所有列,如下所示:

      protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
      {
            GridViewRow row = e.Row;
            List<TableCell> columns = new List<TableCell>();
    
            foreach (DataControlField column in GridView1.Columns)
            {
                TableCell cell = row.Cells[0];
                row.Cells.Remove(cell);
                columns.Add(cell);
            }
    
            row.Cells.AddRange(columns.ToArray());
        }
    

    在这里找到文章:http://geekswithblogs.net/dotNETvinz/archive/2009/06/03/move--autogenerate-columns-at-leftmost-part-of-the-gridview.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-06
      • 2012-07-25
      • 2010-12-23
      • 1970-01-01
      • 2011-10-19
      • 2014-04-10
      • 2010-09-19
      • 2017-06-30
      相关资源
      最近更新 更多