本文介绍了在gridview中最右边的位置动态添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的asp
this is my asp
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound" DataKeyNames="head_code" >
</asp:GridView>
</div>
</form>
</body>
这是我的代码。
This is my code.
protected void Page_Load(object sender, EventArgs e)
{
hitechLatestEntities database = new hitechLatestEntities();
GridView1.DataSource = database.HEADs;
TemplateField tfObject = new TemplateField();
tfObject.HeaderText = "Sub-Heads Details";
tfObject.ItemTemplate = new WebForm1(ListItemType.Item);
GridView1.Columns.Add(tfObject);
GridView1.DataBind();
}
我想在gridview1的最右边这个最近添加的列。现在它出现在最左边。
I want this recently added column at right most place of the gridview1. For now it is appearing at left most.
推荐答案
DataControlFieldCollection allcolumns = GridView1.Columns;
GridView1.Columns.Clear();
GridView1.Columns.Add(allcolumns[0]); // you can change the index in which order u need to display
GridView1.Columns.Add(allcolumns[1]);
GridView1.Columns.Add(allcolumns[2]);
GridView1.Columns.Add(allcolumns[3]);
GridView1.DataBind();
这篇关于在gridview中最右边的位置动态添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!