I searched for searches because I had the same question and I played, and found that if I added "ORDER BY [Field Name]" in my SQL statement and enabled sorting, whenever I clicked on the header, the order of any of the columns! I see that this is a very old thread, but maybe this will help in the future for someone else. As a deeper answer, here is my code for my data source:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/webvideos.mdb" DeleteCommand="DELETE FROM [Docs] WHERE [ID] = ?" InsertCommand="INSERT INTO [Docs] ([ID], [Filename], [Label], [Section], [Index]) VALUES (?, ?, ?, ?, ?)" SelectCommand="SELECT * FROM [Docs] ORDER BY ID" UpdateCommand="UPDATE [Docs] SET [Filename] = ?, [Label] = ?, [Section] = ?, [Index] = ? WHERE [ID] = ?">
And here is my gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" AllowPaging="True" PageSize="20" AllowSorting="True"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Label" HeaderText="Label" SortExpression="Label" /> <asp:BoundField DataField="Filename" HeaderText="Filename" SortExpression="Filename" /> <asp:BoundField DataField="Section" HeaderText="Section" SortExpression="Section" /> <asp:BoundField DataField="Index" HeaderText="Index" SortExpression="Index" /> </Columns> </asp:GridView>
source share