nested gridview get parent row

后端 未结 5 1860
执笔经年
执笔经年 2021-01-20 22:04

I am using Nested GridViews where each row in the gridview has child gridView. I am using RowDataBound Event of Parent GridView, to Bindin

5条回答
  •  孤独总比滥情好
    2021-01-20 22:42

    Try this

     
                
                    
                    
                        
                            
                            
                                
                                    
                                
                            
                        
                    
                
            
    

    Code behind

    protected void gvParent_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView gvChild = (GridView)e.Row.FindControl("gvChild");
                gvChild.DataSource = GetData();
                gvChild.DataBind();
            }
        }
    
        protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string ID = ((HiddenField)e.Row.Parent.Parent.Parent.FindControl("HdnID")).Value;
            }
        }
    

提交回复
热议问题