Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to display category name as the HeaderContainer using Ajax Toolkit Accordian

$
0
0

Hi,

I would like to display Category Names as the HeaderContainer and questions/answers as the ContentContainer.
So when a user selects a category Name, a list of questions and answers will be shown.

I have 3 tables in db: Category, Questions, Answers
Each category has multiple questions and answers

How do I modify the code below to meet that requirement? Thanks -

=============aspx page

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>  
<asp:Accordion ID="Accordion1"  runat="server"></asp:Accordion>

===========cs code behind page ===============

protected void Page_Load(object sender, EventArgs e)        
{            

string connetionString = "connectionstring goes here";            

string sql = "SELECT category, Question, answer  FROM Questions INNER JOIN Category ON Questions.Category_ID = Category.Category_ID INNER JOIN Answers ON Questions.Question_ID = Answers.Question_ID";            

SqlConnection conn= new SqlConnection(connetionString);            

SqlDataAdapter adapter = new SqlDataAdapter();            

DataSet ds = new DataSet();            

onn.Open();            

SqlCommand command = new SqlCommand(sql, conn);            

adapter.SelectCommand = command;            

 adapter.Fill(ds);            

conn.Close();                        

 int i;            

for (i = 0; i < 10; i++)            

 {                

AccordionPane pane1 = new AccordionPane();                

pane1.ID = "pane" + i;                

pane1.HeaderContainer.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i].ItemArray[0].ToString()));                 pane1.ContentContainer.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i].ItemArray[1].ToString()));                 pane1.ContentContainer.Controls.Add(new LiteralControl(ds.Tables[0].Rows[i].ItemArray[2].ToString()));                

Accordion1.Panes.Add(pane1);           

}

 }


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>