开发者

Filtering on RadGrid not working

开发者 https://www.devze.com 2022-12-17 13:10 出处:网络
I created a RadGrid with a couple of fields for filtering and I can\'t seem to get the filtering to work. I can see it clearly posting back (the ajax spinny circle thing) after typing something in the

I created a RadGrid with a couple of fields for filtering and I can't seem to get the filtering to work. I can see it clearly posting back (the ajax spinny circle thing) after typing something in the filter box, however my results are always the same. I am using the following definition in the aspx file:

<telerik:RadGrid PageSize="4" ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
                    OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" Skin="Black" ShowFooter="True"
                    ShowStatusBar="True" AllowFilteringByColumn="True"
                    EnableLinqExpressions="False">
                    <MasterTableView AllowFilteringByColumn="true" Caption="Select a Customer">
                        <Columns>
                            <telerik:GridTemplateColumn CurrentFilterFunction="StartsWith" HeaderText="First Name" AllowFiltering="true" AutoPostBackOnFilter="true">
                                <ItemTemplate>
                                    <%#GetFirstName(DataBinder.Eval(Container, "DataItem"))%>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Last Name" AllowFiltering="true" AutoPostBackOnFilter="true">
                                <ItemTemplate>
                                    <%#GetLastName(DataBinder.Eval(Container, "DataItem"))%>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Address">
                                <ItemTemplate>
                                    <%#GetAddress(DataBinder.Eval(Container, "DataItem"))%>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:Gri开发者_运维技巧dTemplateColumn HeaderText="Shop">
                                <ItemTemplate>
                                    <%#GetShopName(DataBinder.Eval(Container, "DataItem"))%>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="True">
                        <Selecting AllowRowSelect="true" />
                    </ClientSettings>
                    <PagerStyle Mode="NumericPages" />
                </telerik:RadGrid>

And I got the following in my code behind:

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    BusinessLayer.Customers Customers = new BusinessLayer.Customers();

    Customers.GetBySQLStatement(GetCustomerSQL());

    this.RadGrid1.DataSource = Customers;
}

Any ideas?


Add DataField for each column or use GridBoundColumns rather than GridTemplateColumns.


Your grid definition looks OK to me - not sure where the issue is. I use the Telerik grid from some time now and what I would do if in your shoes would be to debug my code, see what the MasterTableView.FilterExpression value is inside NeedDataSource and whether the returned records are filtered with that expression and passed to the grid.

Dick


Public Sub RadGrid_NeedDataSource(ByVal source As RadGrid, ByVal e As GridNeedDataSourceEventArgs) 'Handles RadGrid.NeedDataSource
    Dim RadGrid As RadGrid = CType(source, RadGrid)
    'Dim nestedItem As GridNestedViewItem = CType(source.NamingContainer, GridNestedViewItem)
    'Dim CustomerID = CType(nestedItem.ParentItem, GridDataItem).GetDataKeyValue(source.Attributes("TableID"))

    Dim gridSortString As String = RadGrid.MasterTableView.SortExpressions.GetSortString()

    Dim args As New DataSourceSelectArguments(gridSortString)

    If gridSortString Is Nothing Then
        RadGrid.DataSource = GetDataTable("SELECT * FROM [" + source.Attributes("TableName") + "] ") 'Where CustomerID = N'" + CustomerID + "'
    Else
        RadGrid.DataSource = GetDataTable("SELECT * FROM [" + source.Attributes("TableName") + "] ORDER BY " & gridSortString) 'Where CustomerID = N'" + CustomerID + "'
    End If

End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消