Issue:
How to add AjaxToolkit Accordion Pane Dynamically in C#
Solution:
In the below code, it iterate thought a List/Dictionary of custom object BannerList and creates Accordion Panes dynamically. The code is part of a sample I was working on. But it will help you understand the idea.
foreach (KeyValuePair<int, List<Banner>> entry in BannerList)
{
AccordionPane ap1 = new AccordionPane();
ap1.HeaderContainer.Controls.Add(new LiteralControl(Countries[entry.Key].ToUpper()));
CheckBoxList chkLst = new CheckBoxList();
chkLst.ID = "chkBoxLst" + Countries[entry.Key];
chkLst.RepeatColumns = 5;
foreach(Banner b in entry.Value)
{
chkLst.Items.Add(new ListItem(b.BannerName, b.BannerID.ToString()));
}
Button btnSave = new Button();
btnSave.ID = "btnSave" + Countries[entry.Key];
btnSave.Text = "Save";
Button btnCancel = new Button();
btnCancel.ID = "btnCancel" + Countries[entry.Key];
btnCancel.Text = "Cancel";
ap1.ContentContainer.Controls.Add(chkLst);
ap1.ContentContainer.Controls.Add(btnSave);
ap1.ContentContainer.Controls.Add(btnCancel);
acc1.Panes.Add(ap1);
}
No comments:
Post a Comment