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

RADPanel and Dynamic Controls

1 Answer 82 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vivek
Top achievements
Rank 1
Vivek asked on 30 Nov 2010, 06:12 PM
Hi,
We have requirement, where in we need to create dynamic controls, so need to add controls like buttons,textbox, radCalenderPicker and few other controls, we are facing 2 issues currently,
1. We have a remove button, which should remove set of items, which currently I am adding as Items, so we wanted to know, can we use removeatIndex() and wanted to understand this functionality.
2. And second must bigger issue is, whenever we have a post back, the dynamic controls gets disappears, and we can only see the RadPanelBar, so can you guys let us know the better approach.
3. Can we use Repeaters inside a RadPanelBar?

Below is the code Snippet
// This the code snippet which is used to create dynamic controls

protected
override void OnInit(EventArgs e)
        {
            base.OnInit(e);
//Method gets click event name
            myControl = GetPostBackControl(this.Page);
 
            if ((myControl != null))
            {
                if ((myControl.ClientID.ToString() == btnAddDestination.ClientID.ToString()))// "AddDestinations_btnAddDestination"))
                {
                    stDestinationCnt = stDestinationCnt + 1;
                }
            }
 
            if ((myControl != null))
            {
                if ((myControl.ClientID.ToString() == btnAddDestination.ClientID.ToString()))
                {
 
 //stDestination has custom logic, which is used to add number of controls and also keeps track of previous count
                    for (int i = 0; i < stDestinationCnt; i++)
                    {
 
                        // Litrals first line of table
                        LiteralControl literalHeader = new LiteralControl(@"<table border=""0"" width=""100%""><tr>");
                        newChild.Controls.Add(literalHeader);
Label lbldest = new Label();
                        lbldest.ID = "lbldestination" + stDestinationCnt.ToString();
                        lbldest.Text = "Destination:";
                        newChild.Controls.Add(lbldest);
 
                        //Textbox for destination ID
                        LiteralControl literalDestinationIDTxt = new LiteralControl(@"</td><td width=""100px"">");
                        newChild.Controls.Add(literalDestinationIDTxt);
                        TextBox txtdestination = new TextBox();
                        txtdestination.Text = "Destination";
                        txtdestination.ID = "txtDestination" + stDestinationCnt.ToString();
                        newChild.Controls.Add(txtdestination);
  LiteralControl literalRemove = new LiteralControl(@"</td><td rowspan=""4"">");
                        Button btn = new Button();
                        btn.ID = "Remove" + stDestinationCnt.ToString();
                        btn.Text = "Remove";
                        newChild.Controls.Add(btn);
newChild.Visible = true;
 
                        //Add Controls to Panel Bar
                        RadPanDestination.Items.Add(newChild);
}

//ascx design
    <tr><td>
    <telerik:RadPanelBar runat="server" ID="RadPanDestination" Text="Test" ExpandMode="SingleExpandedItem"
        Width="100%" >
        <Items>
            <telerik:RadPanelItem Text="Destinations" Width="100%">
                <ItemTemplate>


                </ItemTemplate>
            </telerik:RadPanelItem>
        </Items>
    </telerik:RadPanelBar>
    </td></tr>
 we are having this code in user control

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 03 Dec 2010, 02:48 PM
Hi Vivek,

Straight to your questions:

1.  you should use RemoveAt(index) method of the Controls collection of the item:

item.Controls.RemoveAt(2);

2. Dynamically added controls should be re-added on every postback with the same ID.

3. there should be no problem to place repeaters inside RadPanelBar items template.

All the best,
Yana
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Vivek
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or