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