RadGrid apply filter in codebehind
Asked Answered
C

1

6

I'm trying to set a value in a filter for RadGrid on a dropdown select.

GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("versionId");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = VersionsCB.SelectedValue;
RadGrid1.Rebind();

This does fill the version in the versionId filter box, and sets it to "EqualTo", but the grid is not filtered. What am I missing?

EDIT: the aspx:

<telerik:RadGrid
ID="RadGrid1"
runat="server"
AllowFilteringByColumn="True"
AllowPaging="True"
AllowSorting="True"
AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True"
DataSourceID="SqlDataSource1"
GridLines="None"
AllowAutomaticDeletes="True"
AllowAutomaticInserts="True"
AllowAutomaticUpdates="True"
PageSize="50"
Skin="Hay">

    <ClientSettings>
        <Scrolling AllowScroll="False" UseStaticHeaders="False" ScrollHeight="620"/>
    </ClientSettings>

    <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="id" CommandItemDisplay="TopAndBottom">

        <Columns>
            <telerik:GridBoundColumn DataField="id" DataType="System.Int32" HeaderText="id" ReadOnly="True" SortExpression="id" UniqueName="id"></telerik:GridBoundColumn>
            .
            .
            .
            <telerik:GridBoundColumn DataField="versionId" DataType="System.Int32" HeaderText="versionId" ReadOnly="False" SortExpression="versionId" UniqueName="versionId"></telerik:GridBoundColumn>
        </Columns>

    </MasterTableView>

    <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>

</telerik:RadGrid>
Crites answered 19/2, 2011 at 14:32 Comment(1)
Can you share the code for the RadGrid from your aspx page.Cavalryman
C
9

Try this:

RadGrid1.MasterTableView.FilterExpression = "([versionId] = "+VersionsCB.SelectedValue+")";    
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("versionId");    
column.CurrentFilterFunction = GridKnownFunction.EqualTo;    
column.CurrentFilterValue = VersionsCB.SelectedValue;    
RadGrid1.Rebind();

And at the .aspx file modify your RadGrid definiton:

<telerik:RadGrid ID="RadGrid1" runat="server" EnableLinqExpressions="False" ...
Chinkapin answered 4/4, 2011 at 12:37 Comment(2)
I already tried that, but I get an Expression expected error on the line RadGrid1.Rebind();Crites
Oh, i did forget the most important. At the ASPX file modify your RadGrid definition. Add nableLinqExpressions="False": <telerik:RadGrid ID="RadGrid1" EnableLinqExpressions="False" ...Chinkapin

© 2022 - 2024 — McMap. All rights reserved.