Hi,
I am using nested datagrids from Nested GridView Example in ASP.Net using C# and VB.Net.
On the inner grid I am allowing the user to delete rows.
However when the page postback I am unable to reopen the row that was opened.
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?
.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);
}
}