1

I am using nested datagrids from www.aspsnippets.com

On the inner grid I am allowing the user to delete rows.

However when the page posts back I am unable to reopen the row that was opened and no of all rows on the datagrid.

I have tried the code behind to open the row in nested datagrid but is not expanded.

The code was unsuccessful.

How can I have the row expanded when the page posts back?

.javascript

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

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

$(function () {
    $("[id*=IsExpanded]").each(function () {
        if ($(this).val() == "1") {
            $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $("[id*=pnlOrders]", $(this).closest("tr")).html() + "</td></tr>")
            $("[src*=plus]", $(this).closest("tr")).attr("src", "images/minus.png");
        }
    });
})

.aspx

<Columns>
    <%--START SUBGRIDVIEW--%>
    <asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
        <ItemTemplate>
            <img alt="" style="cursor: pointer" src="/img/plus.png" class="ddl_Class_new" />
            <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                <asp:GridView ID="gv_Child" runat="server"
                    AutoGenerateColumns="false"
                    DataKeyNames="sID"
                    CssClass="mGrid" HorizontalAlign="Center">
                    <Columns>
                    .....
                    </Columns>
                </asp:GridView>
            </asp:Panel>
            <asp:HiddenField ID="IsExpanded" runat="server" />
        </ItemTemplate>
    </asp:TemplateField>
    <%--END SUBGRIDVIEW--%> 
    .....
</Columns>

.cs

   protected void btn_Click(object sender, ImageClickEventArgs e)
    {
        if (!String.IsNullOrEmpty(Mp.Container.sMt))
        {
            ImageButton imgbtn = (ImageButton)sender;
            GridViewRow row = (GridViewRow)imgbtn.NamingContainer;

            HiddenField hiddenField = (HiddenField)row.FindControl("hf_resID");
            string sID_contents = hiddenField.Value.ToString();

            string FLabel = row.Cells[3].Text.ToString();

            using (MySqlConnection myConnectionString =
              new MySqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
            {
                using (MySqlCommand cmd =
                    new MySqlCommand("SP", myConnectionString))
                {
                    cmd.Connection.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("sID_contents", sID_contents.ToString());
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                    this.BindData();

                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        HiddenField IsExpanded = (HiddenField)row.FindControl("IsExpanded");
                        IsExpanded.Value = Request.Form[IsExpanded.UniqueID];
                    }

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + FLabel.ToString() + "');", true);
                }
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Not enabled');window.location='Default.aspx';", true);
        }
    }

HTML code row not expanded

    <div>
        <table class="mGrid" cellspacing="0" align="Center"
            rules="all" border="1"
            id="ctl00_ContentPlaceHolder1_gvProducts_ctl15_gv_Child"
            style="border-collapse: collapse;">
            <tr>
                <th scope="col">Name row</th>
            </tr>
            <tr>
                <td class="ddl_Class_new" align="center">Value row</td>
                <input type="hidden" 
                    name="ctl00$ContentPlaceHolder1$gvProducts$ctl15$hdnchild" 
                    id="ctl00_ContentPlaceHolder1_gvProducts_ctl15_hdnchild" />
            </tr>
        </table>
    </div>

using-C-and-VBNet.aspx

enter image description here

5
  • can you show html generated of your asp code ?
    – Swati
    Commented Mar 31, 2021 at 14:07
  • @Swati thanks for reply. There are thousands of lines I don't think I can post here ... a part that interests you? Commented Mar 31, 2021 at 14:34
  • you can just show outer div and some content inside that div only 2-3 child div is enough it would be easy to understand where problem might be.
    – Swati
    Commented Mar 31, 2021 at 14:47
  • @Swati Pls see HTML code row not expanded on the question... Commented Mar 31, 2021 at 15:21
  • there is no code expanding . Also , is there any plugin you are using ?
    – Swati
    Commented Apr 1, 2021 at 5:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.