Nested GridView cell value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • renuami
    New Member
    • Feb 2009
    • 15

    Nested GridView cell value

    We have a GridView2 in GridView1 EditTemplate.
    And we have a button (commandname="U pdate") on GridView2.

    When Button1 is clicked GridView1 goes into edit mode and displays GridView2.
    Now when Button2 is Clicked, we want the cell[0] value of GridView2 to be displayed as Label1 Text on GridView1 and come out of the GridView1 edit mode.

    Basically we want to capture gridView2 cell[0] value and display that on Label1 of GridView1.

    We have written the below code. But we are unsure on how to grab GridView2.cell[0] value and display it as Label1 text.

    Can someone please assist us with this?

    Also, we are not sure if we can use rowupdated event for this. Please also guide us which events we should be using to achieve the functionality. Sample code would help us..

    Thanks and much appreciated..


    Code:
    <asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing" Width="434px">
      <Columns>
           <asp:TemplateField>
            <ItemTemplate>
             <asp:Label ID="label1" runat="server" />
             <asp:Button ID="Button1" CommandName="Edit" runat="server" Text="Button" />
            </ItemTemplate>
    <EditItemTemplate>
           <asp:GridView ID="GridView2" runat="server" OnRowUpdated="GridView2_RowUpdated">
               <Columns>
                  <asp:TemplateField>
                  <ItemTemplate>
                   <asp:Button ID="Button2" CommandName="Update" runat="server" Text="Select" />
                   </ItemTemplate>
                </asp:TemplateField>
               </Columns>
         </asp:GridView>
    </EditItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>


    //GridView1 is binded in this method
    Code:
    public void ActivityDataBind()
    {
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    //Child gridView binding in GridView1 Row Editing
    Code:
     
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
        try
        {
        GridView1.EditIndex =e.NewEditIndex;
        ActivityDataBind();
       
        GridView gv=(GridView)(GridView1.Rows[e.NewEditIndex].Cells[0].FindControl("GridView2"));
    
        DataTable dt=new DataTable();
        // All the databinding table stuff code goes here.....
        gv.DataSource = dt;
        gv.DataBind();
        }
        catch(Exception ei)
        {
        Response.Write(ei.Message.ToString());				
        }
    
        }
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Did you try implementing a method that handles the GridView2's RowEditing event?

    -Frinny

    Comment

    • renuami
      New Member
      • Feb 2009
      • 15

      #3
      Yes.


      protected void GridView2_RowEd iting(object sender, GridViewEditEve ntArgs e)
      {
      }

      At the first place when i type GridView2, it is not recognised by VS Intellisense.

      Any idea??

      I tried almost all the methods and no luck.

      Please Advise...

      Thanks

      Comment

      Working...