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

DropDown in filter

5 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Silvio Silva Junior
Top achievements
Rank 2
Silvio Silva Junior asked on 04 Jun 2010, 07:44 PM
Hello guys.

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jun 2010, 07:18 AM
Hello Silvio,

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.








0
Mona
Top achievements
Rank 1
answered on 16 Jul 2010, 03:48 PM

 

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

 

0
Mira
Telerik team
answered on 21 Jul 2010, 02:40 PM
Hello 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mona
Top achievements
Rank 1
answered on 21 Jul 2010, 02:45 PM
Mira:

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
0
Mira
Telerik team
answered on 22 Jul 2010, 01:00 PM
Hello 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Silvio Silva Junior
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Mona
Top achievements
Rank 1
Mira
Telerik team
Share this question
or