提问人:Edward Sheriff Curtis 提问时间:3/31/2021 最后编辑:Edward Sheriff Curtis 更新时间:4/1/2021 访问量:364
如何在 ASP.Net C 中跨 PostBack 扩展嵌套子 GridViews#
How to keep Nested Child GridViews Expanded across PostBack in ASP.Net C#
问:
我正在使用 www.aspsnippets.com 的嵌套数据网格
在内部网格上,我允许用户删除行。
但是,当页面回发时,我无法重新打开已打开的行,并且无法重新打开数据网格上的所有行。
我已经尝试了隐藏的代码来打开嵌套数据网格中的行,但没有展开。
代码不成功。
当页面回发时,如何展开该行?
.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 代码行未展开
<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>
使用-C-and-VBNet.aspx
答: 暂无答案
评论