Reputation: 82276
Question about GridView sorting in VB.NET:
I have a GridView with AutoGenerateColumns = True
<asp:GridView ID="GridView1" FooterStyle-BackColor="Aquamarine"
AutoGenerateColumns="true" AllowSorting="true" OnSorting="Gridview1_Sorting"
AllowPaging="True" PageSize="12" OnRowCreated="GridView1_RowCreated"
RowStyle-Wrap="true" runat="server" Width="100%" >
<HeaderStyle BackColor="#E0E0E0" ForeColor="#000000"/>
<FooterStyle BackColor="Aquamarine" />
<emptydatarowstyle backcolor="#CBE0FD" forecolor="#0000FF"/>
</asp:GridView>
I've declared the sort event handler (OnSorting="Gridview1_Sorting"
), and it works fine.
However, then I change the column title (headers as they are in the DataSet which I get from the database)
GridView1.HeaderRow.Cells(0).Text = "Document" ' "PROC_UID"
GridView1.HeaderRow.Cells(1).Text = "Process Step" ' "PROC_DOC_UID"
When I set the HeaderRow text, I can no longer click on the title to sort (it also is no longer underlined). How do I correct that?
Upvotes: 4
Views: 4480
Reputation: 21088
You can change the column header by aliasing your columns in the sql query used by the grid:
Select ColumnA as [Whatever], ColumnB as [Name It This] From Table ....
Upvotes: 2
Reputation: 4085
See http://forums.asp.net/p/996470/1691883.aspx#1691883
You'll need to find the Link Button within the control set and then update the link text.
Upvotes: 4