This is a migrated thread and some comments may be shown as answers.

Filter grid on dropdown selection change

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 19 Nov 2011, 08:02 AM
Hello to all
i m binding a radgrid on page load initially radgrid's visibility is false on the selection change of dropdown i want to filter datafrom radgrid my code is here but its not work.....

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadGrid1.Visible = true;
        RadGrid1.MasterTableView.FilterExpression = "([totaldis] ='" + DropDownList1.SelectedValue + "=') ";

        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("totaldis");
        column.CurrentFilterFunction = GridKnownFunction.EqualTo;
        column.CurrentFilterValue = DropDownList1.SelectedValue;

        RadGrid1.MasterTableView.Rebind();
   }

radgrid property is

<telerik:RadGrid Skin="Sunset"  OnPreRender="RadGrid1_PreRender" Width="1200px" ID="RadGrid1"
                    AutoGenerateColumns="False" EnableLinqExpressions="false" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="true" GridLines="None" runat="server"
                    ShowFooter="True"  AllowPaging="false" AllowFilteringByColumn="True" Visible="False">
                    <ClientSettings AllowColumnsReorder="true" EnableRowHoverStyle="true" ReorderColumnsOnClient="true"
                        Selecting-AllowRowSelect="True">
                        <Selecting AllowRowSelect="True" />
                    </ClientSettings>
                    <MasterTableView AllowFilteringByColumn="True">
                        <RowIndicatorColumn Visible="True">
                        </RowIndicatorColumn>
                        <Columns>
<telerik:GridBoundColumn HeaderStyle-Width="20px" ItemStyle-Width="20px" HeaderText="Total Income"
                                DataField="tolincome">
                                <HeaderStyle Width="20px"></HeaderStyle>
                                <ItemStyle Width="20px"></ItemStyle>
                            </telerik:GridBoundColumn>

  </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Nov 2011, 10:06 AM
Hello goldy,

<telerik:GridBoundColumn HeaderStyle-Width="20px" ItemStyle-Width="20px" HeaderText="Total Income"
                                DataField="tolincome"  UniqueName="tolincome">

RadGrid1.MasterTableView.FilterExpression = "([tolincome] LIKE \'%" + DropDownList1.SelectedValue + "%\') ";
       GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("tolincome");
       column.CurrentFilterFunction = GridKnownFunction.Contains;
       column.CurrentFilterValue = DropDownList1.SelectedValue;

Thanks,
Jayesh Goyani
0
Jack
Top achievements
Rank 1
answered on 19 Nov 2011, 10:22 AM
Thanks for quick reply but its not working by your coding all rows from grid remove.
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Nov 2011, 10:34 AM
Hello goldy,

Please check below code its works correctly from my side.
<telerik:RadComboBox ID="RadComboBox1" runat="server"  AutoPostBack="true"
           onselectedindexchanged="RadComboBox1_SelectedIndexChanged">
               <Items>
                   <telerik:RadComboBoxItem Text="1" Value="1" />
                   <telerik:RadComboBoxItem Text="2" Value="2" />
               </Items>
           </telerik:RadComboBox>
       <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
        AllowFilteringByColumn="true" EnableLinqExpressions="false">
           <MasterTableView>
               <Columns>
                   <telerik:GridBoundColumn DataField="ID1" HeaderText="ID1" UniqueName="ID1">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="ID2" HeaderText="ID2" UniqueName="ID2">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="ID3" HeaderText="ID3" UniqueName="ID3">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn UniqueName="EditColumn">
                   </telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
               new { ID1 = "1", ID2 = 11, ID3=111},
               new { ID1 = "2", ID2 = 22, ID3=222}
               
           };
           RadGrid1.DataSource = data;
       }
 
       protected void RadComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
       {
           RadGrid1.MasterTableView.FilterExpression = "([ID1] LIKE \'%" + RadComboBox1.SelectedValue + "%\') ";
           GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ID1");
           column.CurrentFilterFunction = GridKnownFunction.Contains;
           column.CurrentFilterValue = RadComboBox1.SelectedValue;
           RadGrid1.MasterTableView.Rebind();
 
       }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jack
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jack
Top achievements
Rank 1
Share this question
or