I created two parentgridview and childgridview .

<asp:GridView ID="ParentGridView" runat="server"
                        AutoGenerateColumns="False"
                        DataSourceID="SqlDataSource1" DataKeyNames="l_no" 
                              onselectedindexchanged="ParentGridView_SelectedIndexChanged">
Columns>
      <asp:TemplateField HeaderText="Letter Number">
            <ItemTemplate>
               <asp:Label id="l_no" Runat="Server" 
               Text='<%# Eval("l_no") %>'/>
                              </ItemTemplate>
                        
            </asp:TemplateField>
      <asp:TemplateField HeaderText="name Department">
            <ItemTemplate>
               <asp:Label id="nam_dep" Runat="Server" 
               Text='<%# Eval("nam_dep") %>'/>
                              </ItemTemplate>
      </asp:TemplateField>
                        <asp:TemplateField HeaderText="View">
            <ItemTemplate>
                  <asp:Button ID="ViewChild_Button" 
                           runat="server" Text="+"   CommandName="Edit" />
                              </ItemTemplate>
         <EditItemTemplate>
                  <asp:Button ID="CancelChild_Button" 
                           runat="server" Text="-" CommandName="Cancel" />
                                          
                              </EditItemTemplate>
   </asp:TemplateField>
</Columns>
</asp:GridView>

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                              ConnectionString="<%$ ConnectionStrings:ABCConnectionString   %>" 
                              SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource>
 
                     
 
                        <br />
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                              ConnectionString="<%$ ConnectionStrings:ABCConnectionString   %>" 
                              SelectCommand="SELECT * FROM [Letter_dept] WHERE ([l_no] = @l_no)">
                              <SelectParameters>
                                    <asp:SessionParameter Name="l_no" SessionField="l_no" Type="String"/>
                              </SelectParameters>
                        </asp:SqlDataSource>

where should i put anthor gridview where .

<asp:GridView ID="GrandChildGridView" runat="server" 
         AllowPaging="true" PageSize="4" 
         DataSourceID="SqlDataSource2">
</asp:GridView>
protected void ParentGridView_OnRowEditing(object sender,GridViewEditEventArgs e)
      {
            int parent_index = e.NewEditIndex;
 
            //to set the edit index of the Parent 
            //grid with that of the current row
            ParentGridView.EditIndex = parent_index;
            ParentGridView.DataBind();
            //find the pubid_lbl containing pub_id in that 
            //particular row by using findcontrol method
            GridViewRow row = ParentGridView.Rows[parent_index];
            Label l_nu = (Label)row.FindControl("l_no");
 
            //save pub_id and edit_index in session for childgridview's use
            Session["l_no"] = l_nu.Text;
            Session["ParentGridViewIndex"] = parent_index;
      }

Make another TemplateField column and in it ItemTemplate. Put your grid view in that ItemTemplate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.