子GridView列数据绑定

时间:2011-09-02 10:31:39

标签: asp.net data-binding gridview datagridview

我正在使用嵌套的gridview,在RowDatabound事件上我根据parentgridview列的某些条件绑定了childgridview。同时我需要知道孩子gridview的列值。我可以这样做吗? 我正在使用此代码: -

protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      GridView gridViewchild = (GridView)e.Row.FindControl("gridView2");
      string custState = ((DataRowView)e.Row.DataItem)["CustState"].ToString();
      if (!string.IsNullOrEmpty(custState))
      {
           gridViewchild .DataSource = MyDataSource;
           gridViewchild .DataBind();
           //now i need to know the childgridview column's data ????
      }
   }
}

1 个答案:

答案 0 :(得分:1)

有几种方法可以实现这一目标:

1-遍历Child GridView的行

foreach (GridViewRow row in childGridView.Rows)
{
     //row.Cells[index];
}

2-使用子GridView的RowDataBound事件