Updating a RadGrid from a PanelBar template

2 posts, 0 answers
  1. Clint
    Clint avatar
    9 posts
    Member since:
    Oct 2011

    Posted 29 Aug 2014 Link to this post

    I have a HeaderTemplate for a RadPanelItem that contains a LinkButton. In the template constructor I pass an ID value that I need the LinkButton to use. The idea is that the PanelBar grows dynamically based on a query. That works fine using the template.

    My issue comes in when I try to click the LinkButton to update the RadGrid. Since the template is a class of its own, it cannot directly reference the RadGrid for passing it a new DateTable based on the ID value, stored within the template.

    I've tried passing a callback function to the template constructor using System.Action<string>. I then try to attach the callback as an EventHandler to the LinkButton's Click event. So far this hasn't done anything for me.

    public class TelerikTemplates
        public class PanelTemplate : ITemplate
            private readonly Label title;
            private readonly LinkButton totalButton;
            public PanelTemplate(string pTitle, int pTotal, string pId, System.Action<string> callback)
                title = new Label();
                title.CssClass = "panelTitle";
                title.Text = pTitle;
                totalButton = new LinkButton();
                totalButton.CssClass = "totalButton";
                totalButton.Text = pTotal.ToString();
                totalButton.Click += delegate(object sender, System.EventArgs e) { callback(pId); };
            public void InstantiateIn(Control pContainer)

    WebForm Code Behind
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
        using (DataTable data = GetData())
            foreach (DataRow dr in data.Rows)
                RadPanelItem titlePanel = new RadPanelItem();
                titlePanel.HeaderTemplate = new TelerikTemplates.PanelTemplate((string)dr["RuleName"], (int)dr["AccountTotal"], (string)dr["RuleId"], populateGrid);
                RadPanelItem subPanel = new RadPanelItem();
                subPanel.ContentTemplate = new TelerikTemplates.ChartAndTableTemplate(dr);
    public void populateGrid(string pId)
        grid.DataSource = GetGridData(pId);

    WebForm Markup
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="author" content="">
        <meta name="description" content="Demo site for home page.">
        <title>Demo: Home (PanelBar)</title>
        <link href="~/Content/less/css/styles.css" rel="stylesheet" />
        <form id="form1" runat="server">
        <asp:Label ID="lblTest" runat="server" Text="Test"></asp:Label>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        <script type="text/javascript">
            //Put your JavaScript code here.
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                      <telerik:AjaxUpdatedControl ControlID="grid" />
                <telerik:AjaxSetting AjaxControlID="grid">
                      <telerik:AjaxUpdatedControl ControlID="grid" />
                <telerik:RadPanelBar Runat="server" Width="100%" ExpandMode="SingleExpandedItem" ID="panelBar">
                <telerik:RadGrid ID="grid" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" />

    Thanks for any possible help!
  2. Viktor Tachev
    Viktor Tachev avatar
    1789 posts

    Posted 03 Sep 2014 Link to this post

    Hello Clint,

    Try to use advanced data binding for the RadGrid. You could handle the NeedDataSource event and use it to set the DataSource for the RadGrid. If you need to rebind the RadGrid explicitly (e.g. when a button is clicked) you could call the Rebind() method.

    If you would like an illustration on how you NeedDataSource event could be used, you would find the following article interesting:

    Viktor Tachev

    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