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

[Solved] Bind RadDropDown in the filtertemplate in codebehind

1 Answer 273 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahesh
Top achievements
Rank 1
Mahesh asked on 13 Aug 2013, 02:41 PM
Hi All,

I need to put a fdropdown filter in the radgrid. I tried to follow the radgrid demo. But in my case, i need to bind the filter dropdown only in codebehind.

The grid is bound in the needdatasource with an arraylist.

the aspx code is like below,

<telerik:GridTemplateColumn UniqueName="Column1" SortExpression="Column1" HeaderStyle-ForeColor="#245E9E"
HeaderText="Column 1" ItemStyle-Wrap="true" Resizable="true" AutoPostBackOnFilter="true"
CurrentFilterFunction="EqualTo" DataField="Column1">
<FilterTemplate>
<telerik:RadComboBox ID=
"RadComboBoxColumn1" DataTextField="Column1" DataValueField="Column1"
Height="200px" AppendDataBoundItems="true" 
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Column1").CurrentFilterValue %>' 
runat="server" OnClientSelectedIndexChanged="TitleIndexChanged">
<Items>
<telerik:RadComboBoxItem Text=
"All" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID=
"RadScriptBlock1" runat="server">
<script type=
"text/javascript">
function TitleIndexChanged(sender, args)
{
var tableView = $find(
"<%# ((GridItem)Container).OwnerTableView.ClientID %>");
tableView.filter(
"Column1", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<asp:Label ID=
"LblColumn1" Text='<%#Eval("Column1")%>' runat="server">
</asp:Label>
<asp:Label ID=
"LblDataSourceType" Text='<%#Eval("DataSourceType")%>' runat="server" Visible="false">
</asp:Label>
</ItemTemplate>
<HeaderStyle Width=
"280px" />
<ItemStyle Font-Names=
"Arial" Font-Size="11px" Wrap="true" />
</telerik:GridTemplateColumn>


Can anybody please help on this an explain me how can i bind the filter dropdown from codebehind?

Thanks in advance

Thanks,
Mahesh O A


1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 16 Aug 2013, 11:28 AM
Hi Mahesh,

You have several options to bind the combo dynamically:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem filterItem = e.Item as GridFilteringItem;
        RadComboBox combo = filterItem.FindControl("RadComboBoxColumn1") as RadComboBox;
 
        combo.DataSource = new string[] { "Berlin", "Hanari Carnes", "London" };
    }
}

Or:
<telerik:RadComboBox ... OnInit="RadComboBoxColumn1_Init">
C#:
protected void RadComboBoxColumn1_Init(object sender, EventArgs e)
{
    RadComboBox combo = sender as RadComboBox;
    combo.DataSource = new string[] { "Berlin", "Hanari Carnes", "London" };
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Mahesh
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or