I am using nestred gridview. showing parent gridview records.. if any of row has records of child gridview. i am showing using expand and collopase button. this works fine. But this works when you expand on (+ symbol image). it shows child gridview and when collopase(- symbol image), child gridview hides. aspx.cs protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (SqlConnection con = new SqlConnection(sqlconn)) { con.Open(); string sqlqry = "select figno,name,childflag from parentview"; SqlCommand cmd = new SqlCommand(sqlqry,con); SqlDataAdapter adap = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adap.Fill(dt); C1GridView1.DataSource = dt; C1GridView1.DataBind(); } } } // onrowdatabound action protected void childgridbound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label lblflag = (Label)e.Row.FindControl("lblchild"); if(lblflag=="Y") { using (SqlConnection con = new SqlConnection(sqlconn)) { con.Open(); string sqlqry = "select id, descript from childgrid"; SqlCommand cmd = new SqlCommand(sqlqry,con); SqlDataAdapter adap = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adap.Fill(dt); GridView gvSub = e.Row.FindControl("gvsubstitue") as GridView; gvSub.DataSource = dt; gvSub.DataBind(); } } else{ } } } aspx: //javascript: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $("[src*=plus]").live("click", function () { $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>") $(this).attr("src", "../image/Parts/minus.png"); }); $("[src*=minus]").live("click", function () { $(this).attr("src", "../image/Parts/plus.png"); $(this).closest("tr").next().remove(); }); </script> <asp:GridView ID="C1GridView1" Width="1138px" runat="server" ShowFooter="true" OnRowDataBound="childgrid_bound" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="FIG#"> <ItemTemplate> <!-- subgridview for sub items if exists for part--> <img id="imgpartsub" runat="server" alt = "" style="cursor: pointer" src="../Image/Parts/plus.png" /> <asp:Panel ID="pnlOrders" runat="server" Style="display: none"> <asp:GridView ID="gvsubstitue" runat="server" AutoGenerateColumns="false" > <Columns> <asp:TemplateField HeaderText="Id"> <ItemTemplate> <asp:Label ID="lblidsub" runat="server" Text='<%# Eval("id") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label> </ItemTemplate><ItemStyle Width="130px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Descript"> <ItemTemplate> <asp:Label ID="lbldessub" runat="server" Text='<%# Eval("descript") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label> </ItemTemplate><ItemStyle Width="130px" /> </asp:TemplateField> </Columns> </asp:GridView> </asp:Panel> <asp:Label ID="lblmfgsub" runat="server" Text='<%# Eval("figno") %>' Font-Names="Sans-Serif" Font-Size="12px"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="NAME"> <ItemTemplate> <asp:Label ID="lblpartname" Width="278px" runat="server" Font-Size="12px" Font-Names="Sans-Serif" Text='<%# Eval("name") %>' ></asp:Label> </ItemTemplate> <asp:TemplateField HeaderText="ChildFLAG"> <ItemTemplate> <asp:Label ID="lblchild" Width="278px" runat="server" Font-Size="12px" Font-Names="Sans-Serif" Text='<%# Eval("childflag") %>' ></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> This works fine when you click on + and - (expand/collapse). In my case. once page load over, if any parent gridview has child gridview, it should have expaned automatically(- symbol) Then asusual + and - click (collopse and expand)) should work. Thank you.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)