Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi...The code is working fine.. whenever I'm clicking + image it's expanding child grid.

But the problem once the page is loaded after view button....the plus image is showing... after expanding the grid it is not displaying the minus image and again if i'm collapsing the image is not back to plus image... It's displaying like not supported images..

Can any give solution...

This is My code....

What I have tried:

<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 >" + $(this).next().html() + "</td></tr>")
        $(this).attr("src", "~/Images/minus.png");
    });
    $("[src*=minus]").live("click", function () {
        $(this).attr("src", "~/Images/plus.png");
        $(this).closest("tr").next().remove();
    });
</script>



ASP CODE


<asp:GridView ID="GvDetailPrimary" runat="server" AutoGenerateColumns="false" DataKeyNames="UHIDNO"
             CssClass="table table-striped table-bordered table-hover" EditRowStyle-HorizontalAlign="Center" OnRowDataBound="gvDetailReport_rowdatabound">

           <Columns>

               <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center" >
                <ItemTemplate>

                    <asp:Image ID="img_expand" runat="server" style="cursor: pointer" ImageUrl="~/Images/plus.png" />
                    <asp:Panel ID="pnldepend" runat="server" Style="display: none">

                      <asp:GridView ID="GvDetailDepend" runat="server" AutoGenerateColumns="false" CssClass = "table table-striped table-bordered table-hover">
                           <Columns>
                                 <asp:TemplateField HeaderText="Dependents" Visible="TRUE" ItemStyle-HorizontalAlign="Center" >
                                 <ItemTemplate>
                                      <asp:Label ID="lbldepname" runat="server" Text='<%#Eval("Membername") %>' Width="20%" align="center"></asp:Label>
                                 </ItemTemplate>
                                 </asp:TemplateField>

                                 <asp:TemplateField HeaderText="Age" Visible="TRUE" ItemStyle-HorizontalAlign="Center" >
                                 <ItemTemplate>
                                      <asp:Label ID="lbldepage" runat="server" Text='<%#Eval("age") %>' Width="20%" align="center"></asp:Label>
                                 </ItemTemplate>
                                 </asp:TemplateField>

                             </Columns>
                          </asp:GridView>

                      </asp:Panel>
              </ItemTemplate>
              </asp:TemplateField>

        <asp:TemplateField HeaderText="UHIDNO" ItemStyle-HorizontalAlign="center">
               <ItemTemplate>
                   <asp:Label ID="lbluhidno" runat="server" Text='<%#Eval("UHIDNO") %>' align="center"></asp:Label>
               </ItemTemplate>
               </asp:TemplateField>
 </Columns>
         </asp:GridView>



Code behind in onrowdatabound

protected void gvDetailReport_rowdatabound(object sender, GridViewRowEventArgs e)
 {
     SqlDataReader objSqlDataReader = null;
     try
     {

         if (e.Row.RowType == DataControlRowType.DataRow)
         {

             Label uhid = (Label)e.Row.FindControl("lbluhidno");

             GridView gridbind = (GridView)e.Row.FindControl("GvDetailDepend");
             objSqlDataReader = SP.DMLQuery_DetailReportDepen(uhid.Text);
             DataTable dt = new DataTable();
             dt.Load(objSqlDataReader);
             if (dt.Rows.Count > 0)
             {
                 gridbind.DataSource = dt;
                 gridbind.DataBind();
             }

         }
     }

     catch (Exception ex)
     {
         oErrorLog.WriteErrorLog(ex.ToString());
     }

  }
Posted
Updated 4-Mar-17 0:27am
v7

Hope this will help you.

Try this,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js" ></script>


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

        $("[src*=minus]").on("click", function () {
            $(this).attr("src", "Images/plus.png");
            $(this).closest("tr").next().remove();
        });


the value of src attribute will make sense.
 
Share this answer
 
v2
This code is working fine finally...

<script type="text/javascript">
      $(function () {
          $("[src*=minus]").each(function () {
              $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>");
              $(this).next().remove()
          });
      });
    </script>

<pre> <asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_ChildGrid" ImageUrl="~/Images/plus.png" CommandArgument="Show" />

protected void Show_Hide_ChildGrid(object sender, EventArgs e)
        {
            SqlDataReader objSqlDataReader = null;
            try
            {
                ImageButton imgShowHide = (sender as ImageButton);
                GridViewRow row = (imgShowHide.NamingContainer as GridViewRow);
                if (imgShowHide.CommandArgument == "Show")
                {

                    row.FindControl("pnlLifts").Visible = true;
                    imgShowHide.CommandArgument = "Hide";
                    imgShowHide.ImageUrl = "~/Images/minus.png";
                   // Nested Grid code...
                }

                else
                {
                    row.FindControl("PanelID").Visible = false;
                    imgShowHide.CommandArgument = "Show";
                    imgShowHide.ImageUrl = "~/Images/plus.png";

                }

            }
 
Share this answer
 
v2

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