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
we are having this code in user control
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>