先来张效果图
gridview 中嵌套gridview的原理是这样的,在父gridview中建一个摸板列,然后再模版列当中在放入子gridview,然后再父gridview的OnRowDataBound事件中在对子gridview进行数据绑定,首先要获取子gridview的控制权,然后进行数据绑定
protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
utils util=new utils();
HiddenField hf_year=(HiddenField)e.Row.FindControl("hf_year");
if (hf_year != null)
{
string path = hf_year.Value.ToString();
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gvMajor = (GridView)e.Row.FindControl("gvMajor");
gvMajor.DataSource = util.GetMajorName(path);
gvMajor.DataBind(); }
}