Gridview列索引位置动态变化 [英] Gridview column index positions change dynamically

查看:62
本文介绍了Gridview列索引位置动态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam有一个包含3个数据列的数据表。

我想在第1列之后插入新数据列。

例如。我有一个带有列的数据表Name ,地址,州

我想在姓名和地址之间插入一个新专栏专业。

请告诉我怎么做

Iam having a datatable with 3 data columns.
I want to insert the new data column after column 1.
eg.I have a datatable with columns "Name","Address","State"
I want to insert a new column "Profession" between Name and Address.
Please let me know how to do that

推荐答案

你可以使用 insert ,如下图所示:



you can use insert as shown below :

DataControlField field = new AutoGeneratedField("ProductId");
field.HeaderText = "Product Id";

this.GridView2.Columns.Insert(1, field);
this.GridView2.DataBind();





以上代码将在索引1处插入列。



above code will insert column at index 1.


If you want add new column at '0' Index of table then use this
----------------------------------------------------------------

DataTable dt = new DataTable();//Your DT
DataColumn col1 = new DataColumn("Profession", System.Type.GetType("System.String"));
col1.AllowDBNull = true;
col1.DefaultValue = "";
dt.Columns.Add(col1);
col1.SetOrdinal(0);


这篇关于Gridview列索引位置动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆