locked
Editing row in child nested gridview in C# RRS feed

  • Question

  • User1151703306 posted

    Hello there, I hope in your help.

    I need editing row on nested ( child ) gridview.

    This is my code but the editing open always the same id :

    > SELECT * FROM doTable WHERE sID IN ('72')

        protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView g2 = (GridView)sender;
            g2.EditIndex = e.NewEditIndex;
    
            int customerId = (int)g1.DataKeys[e.NewEditIndex].Value;
    
            sql = @String.Format(" SELECT * FROM `doTable` ");
            sql += String.Format(" WHERE sID IN ('{0}') ", customerId);
    
            Response.Write(sql);
    
            g2.DataSource = GetData(sql);
            g2.DataBind();
    
        }

    How to access DataKey values of Child gridview in c# ?

    Can you help me ?

    Thursday, October 3, 2019 1:17 PM

Answers

  • User1151703306 posted

    Solved, thanks you.

        protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView g2 = (GridView)sender;
            g2.EditIndex = e.NewEditIndex;
    
            GridViewRow gvCustomerRow = g2.NamingContainer as GridViewRow;
            int customerId = (int)g1.DataKeys[gvCustomerRow.RowIndex].Value;
    
            sql = @String.Format(" SELECT * FROM `doTable` ");
            sql += String.Format(" WHERE sID IN ('{0}') ", customerId);
    
            g2.DataSource = GetData(sql);
            g2.DataBind();
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 4, 2019 5:42 AM

All replies

  • User61956409 posted

    Hi Golia,

    Golia

    I need editing row on nested ( child ) gridview.

    This is my code but the editing open always the same id

    I did a test on my side, and I can get editing row index of child GirdView and DataKey value of parent GridView as expected. Please debug the code step by step inside GridView2_RowEditing and check if you can get expected editing row index of child GirdView first, then check whether the value(s) you expect are in collections of g1.DataKeys.

    With Regards,

    Fei Han

    Friday, October 4, 2019 3:26 AM
  • User1151703306 posted

    Solved, thanks you.

        protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView g2 = (GridView)sender;
            g2.EditIndex = e.NewEditIndex;
    
            GridViewRow gvCustomerRow = g2.NamingContainer as GridViewRow;
            int customerId = (int)g1.DataKeys[gvCustomerRow.RowIndex].Value;
    
            sql = @String.Format(" SELECT * FROM `doTable` ");
            sql += String.Format(" WHERE sID IN ('{0}') ", customerId);
    
            g2.DataSource = GetData(sql);
            g2.DataBind();
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 4, 2019 5:42 AM