2011-04-07 84 views
0

我有一个基于查询到数据库填充的gridview。我试图在我的gridview上添加排序,但是我无法让我的列标题可点击。我已经允许排序设置为true,并且我有我的OnSorting事件集。我的专栏有几种不同的类型。我知道我需要在我的代码背后的代码,但由于某种原因,我无法点击标题。任何帮助我失去了什么将不胜感激。我不能让我的gridview点击的标题能够排序

<asp:GridView ID="Grid1" runat="server" 
     AutoGenerateColumns="False" 
     OnSelectedIndexChanging="Selected_Row_Changing" 
     DataKeyNames="ApplicationId" 
     AllowPaging="True" 
     OnPageIndexChanging="Grid1_PageIndexChanging" 
     AllowSorting="True" 
     OnSorting="Grid1_Sorting" 
     OnRowCreated="OnRowCreated" 
     OnRowCommand="Grid1_RowCommand" 
     OnRowDataBound="Grid1_RowDataBound"> 

     <Columns> 
      <asp:templatefield ...> 
       <itemtemplate> 
        <asp:linkbutton .../> 
       </itemtemplate> 
      </asp:templatefield> 

      <asp:BoundField ... /> 

      <asp:HyperLinkField ... /> 

      <asp:ButtonField ... /> 

     </Columns> 
    </asp:GridView> 

回答

5

您没有设置SortExpression,对吗?

例如:

<asp:boundfield datafield="CompanyName" 
    headertext="CompanyName" 
    headerstyle-wrap="false" 
    sortexpression="CompanyName"/> 
0

确保你没有设置页眉模板而设置的HeaderText属性为模板列