
I'm using this example: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx
My doubt is: If I have 2 or more columns in my grid, and I need to put dropdown filter in each one, I really need to create a custom .cs page for each column?
If not, what's the suggestion?
Thanks in advance guys.
Have a nice Weekend.
Regards.
5 Answers, 1 is accepted

A better solution for creating columns with dropdown filters is by using 'FilterTemplate'. We can use a RadCombobox to select the available items on which to filter, and nest it in the filter template of a template column.
There are are two possible approaches to achieve this. In the first approach when the user selects an item in the combo, the SelectedIndexChanged client side handler is raised and invoke the filter command in the event handler. Another approach, is to use server side code to set the filter expression for the grid control manually.
You can refer the following documentation and demo for detail explanation on this.
Filter template
Grid / Filter Templates
Hope this information helps you,
Shinu.

Hello
I am trying to add ItemTemplate, EditItemTemplate and FilterTemplate programmatically to the following grid depending on data type of the column.
For a list, there are classes defined like :
DropDownListItemTemplate
: ITemplate
DropDownListEditItemTemplate
: ITemplate, IBindableTemplate
DropDownListFilterItemTemplate
: ITemplate
and code like:
case "Lookup":
gridColumn.ItemTemplate =
new DropDownListItemTemplate(properties.DataField, luObject.GetType(), CurrentLOB);
gridColumn.EditItemTemplate =
new DropDownListEditItemTemplate(properties.DataField, luObject.GetType(), CurrentLOB);
gridColumn.FilterTemplate =
new DropDownListFilterItemTemplate(properties.DataField, luObject.GetType());
break;
The grid is rendered correctly with the drop down in the filter column. However if I click on Edit Icon, I get the following error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
If I remove the FilterTemplate and remove that line of code , everything works correctly. I can add and edit using the drop down in the edit template.
case "Lookup":
gridColumn.ItemTemplate =
new DropDownListItemTemplate(properties.DataField, luObject.GetType(), CurrentLOB);
gridColumn.EditItemTemplate =
new DropDownListEditItemTemplate(properties.DataField, luObject.GetType(), CurrentLOB);
break;
Here is the grid column declaration:
<
Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton"
UniqueName="EditControl" ItemStyle-HorizontalAlign="Center"
meta:resourcekey="GridEditCommandColumnResource1" >
<HeaderStyle Width="35px" />
<ItemStyle HorizontalAlign="Center" Wrap="False"></ItemStyle>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn Groupable="false" DataField="Code" DataType="System.String"
Visible="False" ReadOnly="true" UniqueName="Code"
meta:resourcekey="GridBoundColumnResource7" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder0" meta:resourcekey="GridTemplateColumnResource1" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder1" meta:resourcekey="GridTemplateColumnResource2" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder2" meta:resourcekey="GridTemplateColumnResource3" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder3" meta:resourcekey="GridTemplateColumnResource4" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder4" meta:resourcekey="GridTemplateColumnResource5" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder5" meta:resourcekey="GridTemplateColumnResource6" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder6" meta:resourcekey="GridTemplateColumnResource7" />
<telerik:GridTemplateColumn Groupable="false" Visible="False"
UniqueName="PlaceHolder7" meta:resourcekey="GridTemplateColumnResource8" />
</Columns>
Please help..
Mona
When you add template columns to a grid dynamically, you should create the entire grid in the code-behind in the Page_Init event handler.
For additional information, please take a look at the Programmatic creation help topic.
I hope this helps.
Regards,
Mira
the Telerik team

I seem to have issues only when I try to add the FilterTemplate column. Currently the grid is working great with the addition of Item Template and Edit Item Template columns at runtime. However, now we need to add filtering to the columns and some of those need to be drop down filters..That is what is NOT working.
Thanks
Mona
For the controls inside a template to persist their ViewState, the grid must be generated completely in the code-behind using the Page_Init event. That way, template controls are instantiated before the LoadViewState event of the page.
Please, try creating the entire grid on Page_Init and let me know whether this helps.
Greetings,
Mira
the Telerik team