开发者

How can i use grid view into grid view?

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 w开发者_开发问答ant results in the format that each course name shows its subjects below in list with all course?

How can i do that


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;
}
}
}


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜