views:

1130

answers:

2

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:GridTemplateColumn 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?

A: 

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

Dick Lampard
+1  A: 

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

alan