C# 对已启用分页的gridview进行排序

C# 对已启用分页的gridview进行排序,c#,asp.net,gridview,C#,Asp.net,Gridview,我在gridview上绑定了一个列表 HistoryGrid.DataSource = objGrid; HistoryGrid.DataBind(); AllowSorting="true" AllowPaging="True" <asp:BoundField HeaderText="hits" DataField="numberOfHits" SortExpression="numberOfHits" ItemStyle-HorizontalAlign="Center"

我在gridview上绑定了一个列表

HistoryGrid.DataSource = objGrid;
HistoryGrid.DataBind();

AllowSorting="true" AllowPaging="True"  

<asp:BoundField HeaderText="hits" DataField="numberOfHits" 
  SortExpression="numberOfHits" ItemStyle-HorizontalAlign="Center" />
HistoryGrid.DataSource=objGrid;
HistoryGrid.DataBind();
AllowSorting=“true”AllowPaging=“true”

这不管用。我还需要什么?

如果使用
列表对象作为数据源,则排序功能将无法工作

您可以将
数据表用作Gridview的数据源
,然后它就可以工作了


您可以从这个线程中获得更多想法:

您要绑定到哪种数据源?只有在使用有限数量的数据源中的一个时,才能获得自动排序。我将列表转换为Datatable,现在更改页面时出现问题,然后不显示排序数据。谢谢,我成功了,但在PageIndexChanging for PageGriedView中,我有HistoryGrid.PageIndex=e.NewPageIndex;和数据绑定()。当我转到另一个页面时,它不会对数据进行排序。我的griedview在更新面板中。好的,我使用另一个dataView。再次感谢。