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

How to apply filter on dynamically created columns?

2 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Effat
Top achievements
Rank 1
Effat asked on 02 Jun 2011, 06:52 AM
Hello,

I have a RadGrid which is binded with a data table. I want to apply filter on two columns only.. everything is to be done programmatically because its columns are not statically defined. Can you please suggest how can I apply filtering on two columns of such a radgrid??

Thank you,
Effat

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jun 2011, 08:04 AM
Hello Effat,

In order to achieve this attach ColumnCreated event to your RadGrid and enable filtering for required columns. Here is the sample code that I tried. Hope this helps you.

aspx:
<telerik:RadGrid id="RadGrid1" runat="server"
            OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true"
            oncolumncreated="RadGrid1_ColumnCreated"
               <MasterTableView AutoGenerateColumns="True" />
</telerik:RadGrid>

C#:
protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
  if (e.Column is GridBoundColumn)
  {
     GridBoundColumn col = (GridBoundColumn)e.Column;
     if (col.UniqueName == "ColumnUniqueName")
     {
           col.AllowFiltering = false;
     }
  }
}

Thanks,
Princy.
0
Effat
Top achievements
Rank 1
answered on 02 Jun 2011, 09:09 AM
Thank you Princy for your prompt reply.  The solution was perfect. There is one small thing.. when I filter one column and then erase the filter keywords and try to filter another column, whatever I enter does not show up in the text box of the filter.. what could be possibly wrong?
Tags
Grid
Asked by
Effat
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Effat
Top achievements
Rank 1
Share this question
or