如何从父RowUpdating方法访问嵌套的网格视图行 [英] How to access nested grid view rows from parent RowUpdating method

查看:70
本文介绍了如何从父RowUpdating方法访问嵌套的网格视图行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子网格视图,它添加到父RowDataBound中的父网格视图。在父编辑时,所有子gridview行都可以编辑。这意味着孩子没有自己编辑。如何在父RowUpdating中获取子gridview行以保存已编辑的数据?


I have a child grid view which add to parent grid view in parent RowDataBound. On parent editing, all the child gridview rows are ready to edit. It means that child doesn't have edit itself. How can I get child gridview rows in parent RowUpdating to save edited data?

protected void gvEquipment_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        GridView gvChild = new GridView();
        gvChild.DataSource = dt;
        gvChild.CssClass = "NestedGrid";
        gvChild.RowDataBound += new GridViewRowEventHandler(gvChild_RowDataBound);

        //Create the show/hide button which will be displayed on each row of the main GridView
        Image imgCollapse = new Image();
        imgCollapse.ID = "btnCollapse";
        imgCollapse.ImageUrl = "~/images/Collapse.gif";
        //Add the javascript function to the show/hide button, passing the row to be toggled as a parameter");
        imgCollapse.Attributes.Add("onclick", "javascript: gvrowtoggle(" + (e.Row.RowIndex + e.Row.RowIndex + 2) + ")");

        //Add the expanded details row after each record in the main GridView
        Table tb1 = e.Row.Parent as Table;
        GridViewRow tr = new GridViewRow(e.Row.RowIndex + 1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
        tr.CssClass = "hidden";
        string sr = (e.Row.RowIndex + e.Row.RowIndex + 2).ToString();
        tr.ID = e.Row.RowIndex.ToString();
        TableCell tc = new TableCell();
        tc.ColumnSpan = gvEquipment.Columns.Count + 3;//e.Row.Cells.Count;
        tc.BorderStyle = BorderStyle.None;
        //tc.BackColor = System.Drawing.Color.WhiteSmoke;
        tc.Controls.Add(gvChild);
        tr.Cells.Add(tc);
        tb1.Rows.Add(tr);
        e.Row.Cells[0].Controls.Add(imgCollapse);
        e.Row.CssClass = "GridAltItem";
        gvChild.DataBind();
if (IsEditMode && e.Row.RowIndex == EditIndex)
     {
         // edit mode for childGrid
         for (int i = 0; i < dt.Rows.Count; i++)
             for (int j = 0; j < dt.Columns.Count; j++)
             {
                 TextBox txt = new TextBox();
                 txt.Text = dt.Rows[i][j].ToString();
                 gvChild.Rows[i].Cells[j].Controls.Add(txt);
             }
     }
    }
}

 protected void gvEquipment_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
      GridView gv = (GridView)sender;
      //how to get child gridview controls?
  }

推荐答案

尝试类似

Try something like
protected void gvEquipment_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {

GridViewRow ParentGridRow = gvEquipment.Rows[0];
GridView GridViewChild = (GridView)ParentGridRow.FindControl("GridViewChild");
 
GridViewRow ChildRow = childGridView.Rows[GridViewChild.EditIndex];
 
TextBox txtBoxExample = (TextBox)ChildRow.FindControl("ControlToFind");
}


但现在问题是子网格视图松开了它的编辑值,因为它再次绑定数据绑定。父网格视图具有动态列,并且需要在每个帖子上再次绑定。如何保持子网格值执行更新?
But the problem now is the child Grid view loose its edited values because it binds again on data binding. The parent grid view has dynamic columns and it needs to bind again on every post back. how to keep the child grid values to perform update?


这篇关于如何从父RowUpdating方法访问嵌套的网格视图行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆