【发布时间】:2013-02-23 11:10:06
【问题描述】:
我有一个带有自动生成的Column = "true" 的Gridview 现在我想更改gridview 的OnRowCreated 事件中gridview 列的位置。
我用这个代码
TableCell cell = e.Row.Cells[1];
TableCell cell1 = e.Row.Cells[0];
e.Row.Cells.RemoveAt(1);
e.Row.Cells.RemoveAt(0);
e.Row.Cells.Add(cell1);
e.Row.Cells.Add(cell);
它可以很好地将第 0 列和第 1 列移动到网格视图的最后位置
现在我想将gridview的第三列移动到第一个位置,所以我使用
TableCell cell2 = e.Row.Cells[3];
e.Row.Cells.RemoveAt(3);
e.Row.Cells.AddAt(0, cell2);
但它不起作用....
【问题讨论】:
-
你是如何对 gridview 进行数据绑定的?至于什么?
-
我使用存储过程在 buttonclick 上绑定网格视图
-
用什么数据结构,datatable?
-
在将数据表绑定到 gridview 之前,您不能更改列的顺序吗?
-
你确定.. 我试试... dt.Columns["BookCode"].SetOrdinal(0);它的工作原理。