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

Adding template to FilterTemplate Programmatically

5 Answers 160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ricky
Top achievements
Rank 1
Ricky asked on 14 Jan 2015, 07:07 PM
Hello Anyone,
I guess i am missing something here. I have created an ITemplate as below and adding it to the FilterTemplate of one of the column of RadGrid. 

public class cblItemTemplate : ITemplate
{
    /// <summary>
    /// Create the template
    /// </summary>
    /// <param name="container"></param>
    public void InstantiateIn(Control container)
    {
        Panel pnl = new Panel();
 
        //checkbox
        CheckBoxList cbl = new CheckBoxList();
        cbl.ID = "cblCounty";
        cbl.AutoPostBack = false;
        cbl.DataBinding += cbl_DataBinding;
 
        //button
        Button btn = new Button();
        btn.ID = "btnApply";
        btn.Text = "Apply";
         
        //button
        Button btnClear = new Button();
        btnClear.ID = "btnClear";
        btnClear.Text = "Clear";
 
        pnl.Controls.Add(cbl);
        pnl.Controls.Add(btn);
        pnl.Controls.Add(btnClear);
 
        container.Controls.Add(pnl);
    }
 
    void cbl_DataBinding(object sender, EventArgs e)
    {
        CheckBoxList cbl = (CheckBoxList)sender;
        cbl.Items.Add(new ListItem("County1"));
        cbl.Items.Add(new ListItem("County2"));
    }
}

On first load, i see the template added to the column. But when i click on the Apply button, the template vanishes; i do not see it. I am adding the template on the ColumnCreated event of the radgrid as below:

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
     if (col.UniqueName == "county")
     {
           var cbl = new cblItemTemplate();
           col.FilterTemplate = cbl;
     }
}

Can someone please let me know where i am going wrong? Do i need to add the filtertemplate in a different event?

5 Answers, 1 is accepted

Sort by
0
Ricky
Top achievements
Rank 1
answered on 14 Jan 2015, 09:40 PM
I guess i also need to know how do i bind an event to button where i can rebind the grid with the FilterExpression. Any help is much appreciated!
0
Ricky
Top achievements
Rank 1
answered on 16 Jan 2015, 12:28 PM
Telerik team? No response?
0
Eyup
Telerik team
answered on 19 Jan 2015, 12:43 PM
Hello Ricky,

I've created a sample RadGrid web site to demonstrate how you can modify the filter cell of a given column programmatically. This is the recommended way instead of creating dynamic FilterTemplate. Please run the attached application and let me know if it helps you.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kiran
Top achievements
Rank 1
answered on 12 Nov 2019, 04:49 PM

Hi Eyup,

Can you please provide a VB version of the attachment? I tried converting but somethings not right. 

Thank you.

0
Rumen
Telerik team
answered on 13 Nov 2019, 12:27 PM

Hi Kiran,

Please find attached the requested VB version of the example! Please give it a spin and let me know how it works on your side.

Best Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Ricky
Top achievements
Rank 1
Answers by
Ricky
Top achievements
Rank 1
Eyup
Telerik team
Kiran
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or