在gridview中最右边的位置动态添加列 [英] dynamically added column in gridview at right most place
本文介绍了在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.
推荐答案
请尝试设置gridview.column.display index
您好,对不起我的回答。显示索引是我认为在窗口应用程序中使用的非Web应用程序。
在网站上你可以在链接下面查询。
http://stackoverflow.com/questions/8976153/how-to-reorder-columns-in-gridview-dynamically
please try and set gridview.column.display index
Hi, sorry for my answer. display index is i think used in window applicatio not web application.
in web site you can chek below link .
http://stackoverflow.com/questions/8976153/how-to-reorder-columns-in-gridview-dynamically
试试这样..
try like this..
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中最右边的位置动态添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文