无论我在其中输入什么代码,我的 Telerik RadGrid 都不会排序。我尝试了很多东西,每次单击标题时,箭头和颜色都会改变,但数据会保持相同的顺序。这是我最新的代码块。(我从 Telerik 网站得到这个)请告诉我我在这里做错了什么。
<telerik:RadGrid runat="server" ID="radProductsGrid" Skin="Default" AllowSorting="true"
AllowPaging="true" OnSortCommand="radProductsGrid_SortCommand"
OnNeedDataSource="radProductsGrid_NeedDataSource" AutoGenerateColumns= "false"
GridLines="None" ShowGroupPanel="false" PageSize="100">
<telerik:GridBoundColumn ReadOnly="true" AllowFiltering="true" SortExpression="ItemNumber" DataField="ItemNumber" HeaderText="Item Number" UniqueName="ItemNumber">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn ReadOnly="true" AllowFiltering="true" SortExpression="ProductName" DataField="ProductName" HeaderText="Product Name" UniqueName="ProductName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn ReadOnly="true" AllowFiltering="true" SortExpression="CategoryName" DataField="CategoryName" HeaderText="Category Name" UniqueName="CategoryName">
</telerik:GridBoundColumn>
protected void radProductsGrid_SortCommand(object sender, GridSortCommandEventArgs e)
{
GridTableView tableView = e.Item.OwnerTableView;
if (e.SortExpression == "ItemNumber")
{
e.Canceled = true;
GridSortExpression expression = new GridSortExpression();
expression.FieldName = "ItemNumber";
if (tableView.SortExpressions.Count == 0 || tableView.SortExpressions[0].FieldName != "ItemNumber")
{
expression.SortOrder = GridSortOrder.Descending;
}
else if (tableView.SortExpressions[0].SortOrder == GridSortOrder.Descending)
{
expression.SortOrder = GridSortOrder.Ascending;
}
else if (tableView.SortExpressions[0].SortOrder == GridSortOrder.Ascending)
{
expression.SortOrder = GridSortOrder.None;
}
tableView.SortExpressions.AddSortExpression(expression);
tableView.Rebind();
}
}