Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is what i have done for nested gridview : The jquery i have used to maintain this show hide is as:
XML
<script type="text/javascript">
    // Method for managing opening of gridview on + image and - image


    $("[src*=plus]").live("click", function() {
        $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
        $(this).attr("src", "../Image/minus.gif");
    });

    $("[src*=minus]").live("click", function() {

        $(this).attr("src", "../Image/plus.gif");
        $(this).closest("tr").next().remove();

    });



</script>


  <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" DataKeyNames="num"
                            AutoGenerateColumns="False" Style="font-size: x-small" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
                            OnRowCancelingEdit="GridView1_RowCancelling" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand"
                            OnRowDeleting="GridView1_RowDeleting"  ShowFooter="True"
                            OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting"
                            AllowSorting="true">
                            <RowStyle BackColor="#E3EAEB" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <img alt="" style="cursor: pointer" src="../Image/plus.gif"  />
                                        <asp:Panel  ID="pnlOrders" style="display:none;">


                                            <asp:GridView ID="GridView3" runat="server" CellPadding="4" ForeColor="#333333" DataKeyNames="sno"
                                                OnRowCancelingEdit="GridView3_RowCancelling" OnRowUpdating="GridView3_RowUpdating"
                                                OnRowEditing="GridView3_RowEditing" AutoGenerateColumns="False" Style="font-size: x-small">
                                                <RowStyle BackColor="#E3EAEB" />
                                                <Columns>
                                                    <asp:BoundField DataField="Name" HeaderText="Name" />
                                                    <asp:TemplateField>
                                                    <HeaderTemplate>
                                                    Detailed Head
                                                    </HeaderTemplate>
                                                        <ItemTemplate>

                                                            <asp:Label ID="empdetails" Width="200px" runat="server" Text='<%# Eval("Details") %>'></asp:Label>
                                                             </ItemTemplate>
                                                      <EditItemTemplate>

                                                        <asp:TextBox ID="txtempdetail" Width="200px" runat="server" MaxLength="9" Text='<%# Eval("Details") %>'>
                                                            </asp:TextBox>
                                                      </EditItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="sal" HeaderText="salary" />
                                                    <asp:CommandField ShowEditButton="true" EditText="Edit"  />
                                                </Columns>
                                                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                                                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                                <EditRowStyle BackColor="#7C6F57" />
                                                <AlternatingRowStyle BackColor="White" />
                                            </asp:GridView>

                                        </asp:Panel>
                                    </ItemTemplate>
                                </asp:TemplateField>
                              <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="View" runat="server" Text="View" CommandName="view"
                                            CommandArgument='<%#Container.DataItemIndex+1 %>'></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <HeaderTemplate>
                                        Age</HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblage" Width="80px" runat="server" MaxLength="4" Text='<%# Eval("age") %>'>
                                        </asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtage" runat="server" Text='<%# Eval("age") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <HeaderTemplate>
                                        BloodGroup</HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblBloodGroup" Width="100px" runat="server" MaxLength="9" Text='<%# Eval(" BloodGroup") %>'>
                                        </asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="txtBloodGroup" runat="server" Text='<%# Eval(" BloodGroup") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>


                                <asp:CommandField ShowSelectButton="True" SelectText="Select" />
                                <asp:CommandField DeleteText="Reject" ShowDeleteButton="True" />
                                <asp:CommandField ShowEditButton="true" EditText="Edit" />
                            </Columns>
                            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                            <EditRowStyle BackColor="#7C6F57" />
                            <AlternatingRowStyle BackColor="White" />
                        </asp:GridView>

On server side this is what i am doing :

protected void GridView3_RowEditing(object sender, GridViewEditEventArgs e)
    {
        DataSet ds = new DataSet();
        tBL objBL = new tBL();
        GridViewRow editedRow = GridView1.Rows[e.NewEditIndex];
        //now search row for your control...
        GridView GridView3 = (GridView)editedRow.FindControl("GridView3");




        GridView3.EditIndex = e.NewEditIndex;

        objtxtToTableBL.ViewBL(dt);
        GridView3.DataSource = dt;
        GridView3.DataBind();

    }


    protected void GridView3_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;

    }

    protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

    }


I am binding the nested gridview on rowdatabound of GridView1 and that works fine .

The problem with all this is when i click on the edit button of innergridview(child) it get hide as the page postback . What should i do so that when i click on its edit button the child gridview remains open and it gets hides only when i click on minus button . please help it has already taken 3 days of mine. thank you.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900