2

无论我在其中输入什么代码,我的 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();
        }
    }
4

3 回答 3

0

而不是这样做:

tableView.SortExpressions.AddSortExpression(expression);
tableView.Rebind();

做这个:

radProductsGrid.MasterTableView.SortExpressions.AddSortExpression(expression);
radProductsGrid.Rebind();
于 2014-05-30T17:08:09.853 回答
0

检查 javascript onclick() 事件,它会丢弃排序事件

            var hasChanges, inputs, dropdowns, editedRow;

            function RowClick(sender, eventArgs) {
                if (editedRow && hasChanges) {
                    hasChanges = false;
                    if (confirm("Update changes?")) {

                        $find("<%= RadGrid1.ClientID %>").get_masterTableView().updateItem(editedRow);
                    }
                }
            }
于 2016-01-23T07:55:16.607 回答
-1
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) 'Handles RadGrid1.NeedDataSource
    Dim RadGrid1 As RadGrid = CType(Page.FindControl("RadGrid1"), RadGrid)
    RadGrid1.DataSource = GetDataTable("SELECT کالا.شناسه, کالا.عنوان, کالا.پوشه, بارگیری, کالا.گروه_شناسه, گروه.عنوان AS گروه FROM کالا LEFT JOIN گروه ON کالا.گروه_شناسه = گروه.شناسه")
End Sub

Public Function GetDataTable(ByVal query As String) As DataTable
    Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    Dim conn As SqlConnection = New SqlConnection(ConnString)
    Dim adapter As SqlDataAdapter = New SqlDataAdapter
    adapter.SelectCommand = New SqlCommand(query, conn)
    Dim table1 As New DataTable
    conn.Open()
    Try
        adapter.Fill(table1)
    Finally
        conn.Close()
    End Try
    Return table1
End Function
于 2016-01-23T06:51:20.830 回答