我有一个有2列(+和数据)的网格视图。在单击+号时,它会在同一网格视图中打开一个网格视图。
现在,在子网格视图中,我有一个链接按钮,单击该按钮可以显示一些数据。在回发时,网格视图保持其原始位置,我希望显示子网格视图的原样。
代码。
<asp:GridView ID="grvNeverTouchedQuartile" class="form-table" Width="100%" OnRowCommand="grvNeverTouchedQuartile_RowCommand"
AutoGenerateColumns="false" runat="server" OnRowDataBound="grvNeverTouchedQuartile_RowDataBound"
DataKeyNames="QuartileType">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%--<asp:LinkButton ID="lnkbtnNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'
CommandArgument='<%# Eval("QuartileType") %>' CommandName="NeverTouched"></asp:LinkButton>--%>
<img alt="Image not available" style="cursor: pointer" src="../images/plus.png" />
<asp:Panel ID="pnl_NTChildGrid" runat="server" Style="display: none">
<table>
<tr>
<td>
<div style="overflow: auto;">
<asp:GridView ID="grdNTInsuranceData" runat="server" AutoGenerateColumns="false" OnRowCommand="grdNTInsuranceData_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Insurance Name">
<ItemTemplate>
<asp:Label ID="lblNTQuartileType" runat="server" Text='<%# Eval("QuartileType") %>' Visible="false"></asp:Label>
<asp:Label ID="lblNTInsuranceName" runat="server" Text='<%# Eval("InsuranceName") %>' Visible="false"></asp:Label>
<asp:LinkButton ID="lnkbtnNTInsuranceQuartile" runat="server" Text='<%# Eval("InsuranceNameDetails") %>'
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="NeverTouchedInsurance"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quartile[Count - $Value]">
<ItemTemplate>
<asp:Label ID="lblNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'></asp:Label>
<%--<asp:LinkButton ID="lnkbtnNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'
CommandArgument='<%# Eval("QuartileType") %>' CommandName="NeverTouched"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>提前感谢!
发布于 2017-12-18 22:11:00
有一些方法(这不是代码,它只是我的建议,互联网上有代码,或者它是基于经验的),所以在我看来,你可以使用以下情况之一:
1-你应该使用UpdatePanel来防止页面刷新,并将网格放在UpdatePanel中,就像下面这样的示例:
<asp:UpdatePanel ID="panelId" UpdateMode="Conditional" runat="server" >
<ContentTemplate>
<asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false"
AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header">
<Columns>
<ItemTemplate>
<asp:LinkButton ID="lnkbtnNTInsuranceQuartile" runat="server" Text='<%# Eval("InsuranceNameDetails") %>'
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="NeverTouchedInsurance"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>2- lnkbtnNTInsuranceQuartile的runat是server,点击后会出现回发,因此页面会被刷新。你可以将lnkbtnNTInsuranceQuartile更改为<div><a class="x">click here</a><span class="detail"/></div>等HTML元素,然后单击use ajax,然后更新详细信息跨度,如下所示:
$('.x').click(function () {
var $me = this;
$.ajax({
url: 'Your Web Method address',
data: { youData},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//update span here
$me.parent().find('.details.'.html(your response);
},
error: function (x, e) {
}
});
});3-使用客户端网格而不是ASP.Net GridView
4-将折叠的th的id添加到localstorage中,并在页面加载后再次打开它……
5-等...
以上三个步骤都可以根据您的场景来实现...
希望能帮到你
https://stackoverflow.com/questions/47867029
复制相似问题