This is my gridview:
<asp:GridView ID="gridview" runat="server" AutoGenerateColumns="true">
<Columns>
<asp:TemplateField HeaderText="TestColumn">
<ItemTemplate>
<asp:LinkButton ID="lkbtn" runat="server" Text="Edit"
CommandName="Update" CausesValidation="False" ToolTip="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The TestColumn ends up being the first column, but i want it after the auto generated ones.
In the RowDataBound
event handler, you can move the TemplateField cell from the first column to the end of the row:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
TableCell cell = e.Row.Cells[0];
e.Row.Cells.RemoveAt(0);
e.Row.Cells.Add(cell);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With