.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Ajax >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Accordion Control Inside GridView

Posted By:Sasi Prabhu       Posted Date: January 06, 2012    Points: 40    Category: Ajax    URL: http://www.dotnetspark.com  

Displaying the Accordion inside the GridView From Database.
 

Step 1:

Add ScriptManager into Page.

Step 2:

Add Accordion Control



Step 3:

Add the Header and Content Field into Accordion









Step 4:

Add Header Name to the HeaderTemplate from database


<%#Eval("StudentName")%>

Step 5:

Add HiddenField and GridView to the ContentTemplate






Step 6:

Now Bind the Values from Database table in Page_Load Event

con.Open();
SqlCommand cmd = new SqlCommand("select * from student", con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
con.Close();
AccStudent.DataSource = dt.DefaultView;
AccStudent.DataBind();

Step 7:

Add Find the HiddenField and Gridview Control in Accordion ItemDataBound Event and Bind the Database Table

protected void AccStudent_ItemDataBound(object sender, AjaxControlToolkit.AccordionItemEventArgs e)
{
if (e.ItemType == AjaxControlToolkit.AccordionItemType.Content)
{
string IDVal = ((HiddenField)e.AccordionItem.FindControl("hfID")).Value;
con.Open();
SqlCommand cmd = new SqlCommand("select * from subject where StudentID='"+IDVal.Trim()+"' ", con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
con.Close();
GridView gvSubject = new GridView();
gvSubject = (GridView)e.AccordionItem.FindControl("GVSubject");
gvSubject.DataSource = dt.DefaultView;
gvSubject.DataBind();
}
}

Now Build and Run.






     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend