在特定索引处添加单元格

本文关键字:添加 单元格 索引 | 更新日期: 2023-09-27 18:36:02

我有带有自动生成列的网格视图。我在行数据绑定事件中动态添加了一列。

     if (e.Row.RowType == DataControlRowType.DataRow)
    {
        TableCell cell1 = new TableCell();
        e.Row.Cells.Add(cell1);
    }
       // to add header
    else
    {
        TableCell cell1 = new TableCell();
        cell1.Text = "<span style='font-weight:bold'>NAME";
        e.Row.Cells.Add(cell1);
    }   

此列将添加到末尾。我想在索引 2 中添加此列。

有人可以帮我吗?提前谢谢。

在特定索引处添加单元格

改用AddAt(int index, TableCell cell)

例:

e.Row.Cells.AddAt(2, cell1);

希望这会有所帮助!!