Search code examples
c#asp.nettelerikradgrid

Filtering on RadGrid not working


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?


Solution

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