I am having trouble adding new columns to GridView
control from code-behind.
I use DataTable
as a datasource for my GridView
control, and, after binding it, every column that I add to GridView appears at the left side of the control. I need to change it's position.
Please note, that I need to add columns from the code-behind, not from the .aspx
file.
My GridView
definition in .aspx
file:
<asp:GridView ID="devicesTable" runat="server" OnRowEditing="deviceEdit">
</asp:GridView>
And the piece of code, where I try to add a column:
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();
And this results in buttonField
appearing at the left side of the GridView
. How do I change it's position?
Thanks in advance.