This is a migrated thread and some comments may be shown as answers.
How to create asp controls in RadPanelBar
2 Answers 100 Views
This is a migrated thread and some comments may be shown as answers.
Monalisa
Top achievements
Rank 1
Monalisa asked on 15 Jul 2009, 01:16 PM
Hi Telerik,

I am unable to create asp checkbox, button, dropdown etc.. controls in RadPanelBar.
My requirement is to create checkbox, button, dropdown in panel bar and also event for these item should fire.
Could u please help me.
Reply me as soon as possible
Its very urgent.

Thanks,
Monalisa

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 15 Jul 2009, 01:40 PM
Hi Monalisa,

You can checkout the following code snippet in order to add controls to PanelItem and to attach the events dynamically.

ASPX:
 
<telerik:RadPanelBar ID="RadPanelBar1" runat="server"
    <Items> 
        <telerik:RadPanelItem runat="server" Text="Root RadPanelItem1"
            <Items> 
                <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 1"
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelItem> 
        <telerik:RadPanelItem runat="server" Text="Root RadPanelItem2"
            <Items> 
                <telerik:RadPanelItem runat="server" Text="Child RadPanelItem 2"
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelItem> 
    </Items> 
</telerik:RadPanelBar> 

C#:
 
protected void Page_Load(object sender, EventArgs e) 
    Button button = new Button(); 
    button.ID = "Button1"
    button.Text = "My Button"
    button.Click += new EventHandler(button_Click); // Attach event handler 
 
    CheckBox checkbox = new CheckBox(); 
    checkbox.AutoPostBack = true
    checkbox.ID = "CheckBox1"
    checkbox.CheckedChanged += new EventHandler(checkbox_CheckedChanged); // Attach event handler 
 
    (RadPanelBar1.FindItemByText("Child RadPanelItem 1"as RadPanelItem).Controls.Add(button); // Adding button to PanelItem 'Child RadPanelItem 1' 
    (RadPanelBar1.FindItemByText("Child RadPanelItem 2"as RadPanelItem).Controls.Add(checkbox);// Adding button to PanelItem 'Child RadPanelItem 2' 
void checkbox_CheckedChanged(object sender, EventArgs e) 
     
void button_Click(object sender, EventArgs e) 
     

-Shinu.
0
Stuart Hemming
Top achievements
Rank 2
answered on 15 Jul 2009, 01:52 PM
Monalisa,

Shinu beat me top it,  but as I've written it, here's an example doing it all declaratively ...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm10.aspx.cs" Inherits="WebApplication1.WebForm10" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server"
    <div> 
      <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
      </telerik:RadScriptManager> 
       
      <telerik:RadPanelBar ID="RadPanelBar1" runat="server"
        <Items> 
          <telerik:RadPanelItem Text="Normal PanelItem"
            <Items> 
              <telerik:RadPanelItem Text="Child 1"></telerik:RadPanelItem> 
              <telerik:RadPanelItem Text="Child 2"></telerik:RadPanelItem> 
              <telerik:RadPanelItem Text="Child 3"></telerik:RadPanelItem> 
            </Items> 
          </telerik:RadPanelItem> 
          <telerik:RadPanelItem Text="PanelItem with Controls"
            <Items> 
              <telerik:RadPanelItem> 
                <ItemTemplate> 
                  <asp:CheckBox ID="ckbox1" runat="server" OnCheckedChanged="ckbox1_CheckChanged" /> 
                  <br /> 
                  <asp:Button ID="btn1" runat="server" OnClick="btn1_Click" Text="Click me" /> 
                  <br /> 
                  <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" AutoPostBack="true"
                    <asp:ListItem Text="Item 1" Selected="True" ></asp:ListItem> 
                    <asp:ListItem Text="Item 2" ></asp:ListItem> 
                    <asp:ListItem Text="Item 3" ></asp:ListItem> 
                  </asp:DropDownList> 
                </ItemTemplate> 
              </telerik:RadPanelItem> 
            </Items> 
          </telerik:RadPanelItem> 
        </Items> 
      </telerik:RadPanelBar> 
    </div> 
    </form> 
</body> 
</html> 
 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
namespace WebApplication1 
    public partial class WebForm10 : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
 
        } 
 
        protected void ckbox1_CheckChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        protected void btn1_Click(object sender, EventArgs e) 
        { 
 
        } 
 
        protected void ddl1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
 
        } 
    } 

Hope this helps.

Don't forget to mark the question as "answered" if this sorts you out.

--
Stuart
Asked by
Monalisa
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Stuart Hemming
Top achievements
Rank 2
Share this question
or