Adding template to FilterTemplate Programmatically

4 posts, 0 answers
  1. Ricky
    Ricky avatar
    3 posts
    Member since:
    Jan 2015

    Posted 14 Jan 2015 Link to this post

    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?
  2. Ricky
    Ricky avatar
    3 posts
    Member since:
    Jan 2015

    Posted 14 Jan 2015 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricky
    Ricky avatar
    3 posts
    Member since:
    Jan 2015

    Posted 16 Jan 2015 Link to this post

    Telerik team? No response?
  5. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 19 Jan 2015 Link to this post

    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.

     
Back to Top