我在向代码隐藏的GridView
控件添加新列时遇到问题。 我使用DataTable
作为我的GridView
控件的数据源,绑定后,添加到GridView的每一列都出现在控件的左侧。我需要改变它的位置。在GridView中更改动态创建的列的位置 - ASP.NET
请注意,我需要从代码隐藏中添加列,而不是从.aspx
文件中添加列。
我GridView
定义.aspx
文件:
<asp:GridView ID="devicesTable" runat="server" OnRowEditing="deviceEdit">
</asp:GridView>
而且一段代码,在那里我尝试添加一列:
StoredProcedure connection = new StoredProcedure("usp_nsi_mpd_sel");
DataTable dataTable = connection.ExecReader();
ButtonField buttonField = new ButtonField();
buttonField.CommandName = "Select";
buttonField.ButtonType = ButtonType.Button;
buttonField.Text = "Edit";
devicesTable.DataSource = dataTable;
devicesTable.Columns.Add(buttonField);
devicesTable.DataBind();
,这导致buttonField
出现在左侧GridView
。我如何改变它的位置?
在此先感谢。
如果主要问题是动态更改列的顺序,您可以在这里看到我的答案:http://stackoverflow.com/a/28611217/215752 – Hogan