Reorder Columns
1 answer
for this you need to know the data field (the data item you want to bind) and use either template or boundcolumns to accomplish this, e.g .:
automatic generation of column grid
<asp:GridView id="gv" runat="server" AutoGenerateColumns="True">
</asp:GridView>
manually create a column grid
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="My First Column" DataField="myField1" />
<asp:BoundField HeaderText="My Second Column" DataField="myField2" />
<asp:BoundField HeaderText="My Third Column" DataField="myField3" />
<asp:TemplateField HeaderText="My Fourth Column">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("myField4") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can use either BoundField or TemplateField , with a template you can do a lot more, create a dropdown instead of a label, etc ... in a BoundField, the output will always be a label and you can only format the string value using nomenclature. NET, for example {0: d}
You have more predefined templates to use like checkbox, button, hyperlink, command and image.
0
a source to share