代码之家  ›  专栏  ›  技术社区  ›  Stefan Steiger Marco van de Voort

GridView自动生成列和排序

  •  4
  • Stefan Steiger Marco van de Voort  · 技术社区  · 16 年前

    有关VB.NET中网格视图排序的问题:

    我有一个网格视图 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>
    

    我已经声明了排序事件处理程序( OnSorting="Gridview1_Sorting" ,而且工作正常。

    但是,然后我更改列标题(标题与从数据库中获取的数据集中的标题相同)

    GridView1.HeaderRow.Cells(0).Text = "Document" ' "PROC_UID"
    GridView1.HeaderRow.Cells(1).Text = "Process Step" ' "PROC_DOC_UID"
    

    当我设置headerRow文本时,我不能再单击标题进行排序(它也不再带下划线)。 我该如何纠正?

    2 回复  |  直到 10 年前
        1
  •  4
  •   John Hoven    16 年前

    http://forums.asp.net/p/996470/1691883.aspx#1691883

    您需要在控件集中找到链接按钮,然后更新链接文本。

        2
  •  2
  •   Kevin LaBranche    16 年前

    您可以通过在网格使用的SQL查询中为列设置别名来更改列标题:

    Select ColumnA as [Whatever], ColumnB as [Name It This] From Table .... 
    
    推荐文章