tags:

views:

18

answers:

2

hi, i am having a concept like i want to use grid view inside another grid view. this is required as i want to show records with foreign key where there are many related records.

For example i want a output like i am having a table with course name and another table containing subjects of each course.

In output i want results in the format that each course name shows its subjects below in list with all course?

How can i do that

A: 

I believe you are looking for hierarchical gridview.

Few free exemples:

http://msdn.microsoft.com/en-us/magazine/cc164077.aspx

http://www.aspboy.com/Categories/GridArticles/Hierarchical_GridView_With_Clickable_Rows.aspx

Also some professional can be found, for exemple devexpress: http://demos.devexpress.com/ASPxGridViewDemos/

GôTô
+4  A: 

To display grid inside a gird code

Every time a row is databound to the parent grid, a OnRowDataBound event is fired. Use OnRowDataBound event to capture it

OnRowDataBound="gridViewParticipant_RowDataBound"

protectedvoid gridViewParent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gridViewChild = (GridView)e.Row.FindControl("gridViewChild ");
string participantID = ((DataRowView)e.Row.DataItem)["ParticipantID"].ToString();
if (!string.IsNullOrEmpty(participantID))
{
gridViewChild .DataSource = SOURCE;//load data from database based on foriegn key, make sure that you should select that foreign key field in to your data by which you bind parent gridview, i giving here for example ParticipantID 
gridViewChild .DataBind();
}
else
{
gridViewChild .Visible = false;
}
}
}
AsifQadri