Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RadGrid apply filter in codebehind

Tags:

telerik-grid

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>
like image 402
bfi Avatar asked Feb 19 '11 14:02

bfi


1 Answers

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" ...
like image 121
zozzancs Avatar answered Oct 10 '22 01:10

zozzancs