LucaLuca

LucaLuca

  • NA
  • 2
  • 0

Problem with accordion....the complete code is inside! try it please!

Oct 15 2007 5:22 AM
Hi people...i need your help!!

I've this situation:

4 xml files:

- messaggio0.xml

<messaggio>
<titolo>titlemessaggio0</titolo>
<corpo>bodymessaggio0</corpo>
</messaggio>

- messaggio1.xml

<messaggio>
<titolo>titlemessaggio1</titolo>
<corpo>bodymessaggio1</corpo>
</messaggio>

- risposte0.xml

<risposte>
<risposta>
<corpo>body1risposte0</corpo>
</risposta>
<risposta>
<corpo>body2risposte0</corpo>
</risposta>
</risposte>

- risposte1.xml

<risposte>
<risposta>
<corpo>body1risposte1</corpo>
</risposta>
<risposta>
<corpo>body2risposte1</corpo>
</risposta>
</risposte>

a test.aspx file:

<%@ Page Language="C#" CodeFile="test.aspx.cs" Inherits="prova" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<body>
<form id="Form1" runat="server">
<asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager>
<asp:Panel ID="pan" runat="server"></asp:Panel>
</form>
</body>


and test.aspx.cs file:

using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

public partial class test: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Literal div1 = new Literal();
div1.Text = "<div style=\"margin-bottom: 5px;\">" +

"<div style=\"padding: 4px; text-align:center;\"><div>";
pan.Controls.Add(div1);



for (int j = 0; j < 2; j++)
{
AjaxControlToolkit.Accordion acc = new AjaxControlToolkit.Accordion();
acc.ID = j.ToString() + "-acc";
acc.FramesPerSecond = 40;
acc.FadeTransitions = true;
acc.TransitionDuration = 250;
acc.Visible = true;
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~") + "/messaggio" + j.ToString() + ".xml");
LinkButton lb = new LinkButton();
lb.Text = "<div style=\"width:100%;\">" +

"<span style=\"font-size:14px;\">" +
"<font size=\"2\" color=\"#0033FF\"><strong>" + ds.Tables[0].Rows[0].ItemArray[0].ToString() + "</strong></font>" +
"</span>" +

"</div>";
UpdatePanel up = new UpdatePanel();
up.ID = j.ToString() + "-updatepanel";
Literal lbl = new Literal();
lbl.Visible = false;
lbl.ID = j.ToString() + "-label";
lb.ID = j.ToString() + "-link";
lb.CommandArgument = j.ToString();
lb.Click += new EventHandler(lb_Click);
UpdateProgress upr = new UpdateProgress();
upr.ProgressTemplate = new BarGif("blablablablablabla");
upr.ID = j.ToString() + "-updateprogress";
upr.AssociatedUpdatePanelID = j.ToString() + "-updatepanel";
up.ContentTemplateContainer.Controls.Add(upr);
up.ContentTemplateContainer.Controls.Add(lb);
up.ContentTemplateContainer.Controls.Add(lbl);
up.ContentTemplateContainer.Controls.Add(acc);
AsyncPostBackTrigger apbt = new AsyncPostBackTrigger();
apbt.ControlID = j.ToString() + "-link";
apbt.EventName = "Click";
up.Triggers.Add(apbt);
pan.Controls.Add(up);

}
Literal div5 = new Literal();
div5.Text = "</div></div>";
pan.Controls.Add(div5);

}

public class BarGif : TemplateControl, ITemplate
{
private string _barPic;

public BarGif(string template)
{
this._barPic = template;
}

public void InstantiateIn(Control container)
{
LiteralControl lc = new LiteralControl("<b>Please wait...</b>");
container.Controls.Add(lc);
}
}

//Class for Building Pane HTML Template tempales
public class PaneHTMLTemplate : ITemplate
{
private string template;

public PaneHTMLTemplate(string temp)
{
template = temp;
}

public void InstantiateIn(Control container)
{
LiteralControl ltr = new LiteralControl(this.template);
container.Controls.Add(ltr);
}
}


void lb_Click(object sender, EventArgs e)
{
string argument = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
Literal lbl = (Literal)pan.FindControl(argument + "-label");
if (lbl != null)
{
if (lbl.Visible == false)
{
lbl.Visible = true;

DataSet msg = new DataSet();
msg.ReadXml(Server.MapPath("~") + "/messaggio" + argument +".xml");

DataSet reply = new DataSet();
reply.ReadXml(Server.MapPath("~") + "/risposte" + argument + ".xml");

lbl.Text = "<div style=\"width:100%;\">" +

"<p>" + msg.Tables[0].Rows[0].ItemArray[1].ToString() + "</p>";
Accordion acc = (Accordion)pan.FindControl(argument + "-acc");

for (int i = 0; i < reply.Tables[0].Rows.Count; i++)
{
AjaxControlToolkit.AccordionPane pane = new AjaxControlToolkit.AccordionPane();
PaneHTMLTemplate header = new PaneHTMLTemplate("<b>reply # " + (i + 1).ToString() + "</b>");
pane.Header = header;
PaneHTMLTemplate body = new PaneHTMLTemplate(reply.Tables[0].Rows[i].ItemArray[0].ToString());
pane.Content = body;
acc.Panes.Add(pane);
}
lbl.Text += "</div>";

}
else { lbl.Visible = false; lbl.Text = ""; }
}
}
}



and now my problem!

if you load test.aspx, will show two title.

If you click over a title, will be show in async way the message body and the replies for the message (the replies are shown using an accordion).

If you click in the same title, will be close.

But, if you click in the other title when the other message body and replies are shown, then, the body and the replies for this other message will be show.

The problem is that, when the body and replies are loaded for ths message, body of the first message is show, but replies are hidden (accordion will not show)!! why?

Is possible to have a situation like that: two titles opened and the bodies and replies showned correctly and not hidden?

Excuse me for my english, i'm italian! I hope you can understand me and you can help me! If you have a question for me, please, reply this message and ask me! Thank u!