views:

711

answers:

2

Hi, question about gridview sorting in VB.NET:

I have a gridview with autogenerate columns = 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?

+2  A: 

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.

benjynito
Most excellent. Need to replace " " with   etc. HTMLencode the link button text Dim tblThisCell As TableCell For Each tblThisCell In e.Row.Cells Try Dim lnkButton As LinkButton = tblThisCell.Controls(0) Select Case lnkButton.Text Case "DOC_Bezeichnung" lnkButton.Text = "Dokument" End Select Catch ex As Exception MyDebug.MsgBox(ex.Message) End Try Next End If
Quandary
+2  A: 

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 ....
klabranche
best way to do it!
TheVillageIdiot
Also good, but gives me problems because with this method I have to change my query.
Quandary