Create Accordion dynamically from XML
In web application accordion is a very nice using. By using that you can make you website good looking and in a small space you cam put many things. Here am giving you example of a dynamic Accordion which i am loading from a XML file.
To create that using AjaxControlToolkit. In AjaxControlToolkit a control named Accordion is available , i have just load this dynamically and reading data from XML.
Here are the coder to read data from XML and Load accordion dynamically
Here are the coder to read data from XML and Load accordion dynamically
Accordion accordion = new Accordion();
accordion.ID = “AccordionID”;
accordion.SelectedIndex = 0;
accordion.FadeTransitions = true;
accordion.FramesPerSecond = 50;
accordion.TransitionDuration = 250;
accordion.SuppressHeaderPostbacks = true;
string _path = HttpContext.Current.Server.MapPath(@”Sitemap.xml”);
FileStream stream = new FileStream(_path, FileMode.Open , FileAccess.Read, FileShare.ReadWrite);
XmlDocument document = new XmlDocument();
document.Load(stream);
XmlNodeList nodeList = document.GetElementsByTagName(“Item”);
for (int i = 0; i < nodeList.Count; i++)
{
AccordionPane accorPane = new AccordionPane();
Label lbl = new Label();
lbl.ID = “lblControl”;
lbl.Text = nodeList[i].Attributes["name"].Value;
lbl.Width = 200;
lbl.BackColor = System.Drawing.Color.Wheat;
lbl.Style.Add(HtmlTextWriterStyle.MarginBottom, “3px”);
accorPane.HeaderContainer.Controls.Add(lbl);
for (int j = 0; j < nodeList[i].ChildNodes.Count; j++)
{
string name = nodeList[i].ChildNodes[j].Attributes["name"].Value;
Label lbl2 = new Label();
lbl2.ID = “lblControl2″;
lbl2.Text = name;
lbl2.Width = 195;
lbl2.BackColor = System.Drawing.Color.WhiteSmoke;
lbl2.Style.Add(HtmlTextWriterStyle.MarginBottom, “2px”);
lbl2.Style.Add(HtmlTextWriterStyle.PaddingLeft, “5px”);
HyperLink hl = new HyperLink();
accorPane.ContentContainer.Controls.Add(lbl2);
accorPane.ContentContainer.Controls.Add(new LiteralControl(“<br/>”));
}
accordion.Panes.Add(accorPane);
}
PlaceHolder1.Controls.Add(accordion);
stream.Close();
Reference:ashrafur.files.wordpress.com