0

I am working with asp.net page with telerik, in which i have a telerik radgrid, when click on the grid edit, need to fetch some data that matches present scenario and that data in the form of data table containing multiple rows,

Now based on the no of rows in data table i need to generate RadPanelItems programmatically, i achieved this by using the following code

for (int i = 0; i < dtCompletedCust.Rows.Count; i++)
{
   RadPanelItem panelItem = new RadPanelItem();
   panelItem.Text = dtCompletedCust.Rows[i]["CustName"].ToString();
   pnlReviewedCust.Items.Add(panelItem);                        
}

It is successfully adding me the no of RadPanelItems,

Now my requirement is that I need to add content template to each of this newly added RadPanelItem and this content template contains multiple controls, can any one help me or suggest some thing on this?

Gurunadh
  • 453
  • 2
  • 10
  • 24

1 Answers1

1

Create a class that will inherit ITemplate: https://msdn.microsoft.com/en-us/library/system.web.ui.itemplate(v=vs.110).aspx and instantiate it: https://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein(v=vs.110).aspx

Something like:

    RadPanelItem panelItem = new RadPanelItem();
    panelItem.Text = dtCompletedCust.Rows[i]["CustName"].ToString();
    panelItem.ContentTemplate = myITemplateClass;
    pnlReviewedCust.Items.Add(panelItem);

Or use its Controls collection:

    RadPanelItem panelItem = new RadPanelItem();
    panelItem.Text = dtCompletedCust.Rows[i]["CustName"].ToString();
    panelItem.Controls.Add(new LiteralControl(DateTime.Now.ToString()));
    pnlReviewedCust.Items.Add(panelItem);      
rdmptn
  • 5,413
  • 1
  • 16
  • 29
  • Thanks for the reply, This can add the control to Item template and it is always visible but I need to add control to content template so that it cam be expandable, i found some way to do it in http://docs.telerik.com/devtools/aspnet-ajax/controls/panelbar/templates/adding-templates-at-runtime and completed the task – Gurunadh Dec 14 '15 at 06:13
  • the article shows exactly what i was talking about :) glad to hear you got what you needed working – rdmptn Dec 14 '15 at 06:47