如何解决ListView 和 Datapager |在回发时保留动态控件
考虑以下代码:
前端:
<asp:ListView ID="lvClient" runat="server">
<LayoutTemplate>
<table id="tblClientList" class="table table-striped">
<thead>
<tr>
<th></th>
<th>Firstname</th>
</tr>
</thead>
<tr runat="server" id="itemPlaceholder"></tr>
<tr>
<td colspan="11">
<asp:DataPager ID="dpClient" runat="server" PagedControlID="lvClientList" PageSize="30" class="datapagerList">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowNextPageButton="false" RenderNonBreakingSpacesBetweenControls="false" FirstPageText="Première page" PreviousPageText="Précédente" ButtonCssClass="dpLinkPrevious"/>
<asp:NumericPagerField RenderNonBreakingSpacesBetweenControls="false" NumericButtonCssClass="dpLinkPageNo" CurrentPageLabelCssClass="dpLinkPageNo dpLinkPageNoCurrent"/>
<asp:NextPreviousPagerField ShowLastPageButton="false" ShowPreviousPageButton="false" RenderNonBreakingSpacesBetweenControls="false" LastPageText="Dernière page" NextPageText="Suivante" ButtonCssClass="dpLinkNext"/>
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<input id="chckBoxClient" value='<% #Eval("clientNo") %>' type="checkbox" runat="server"/>
</td>
<td runat="server">
<asp:Label runat="server" Text='<% #Eval("firstName") %>' /></td>
</tr>
</ItemTemplate>
后端:
Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
lvClientList.DataSource = datatableOfClients
lvClientList.DataBind()
End If
End Sub
Private Sub lvClientList_PagePropertiesChanging(sender As Object,e As PagePropertiesChangingEventArgs) Handles lvClientList.PagePropertiesChanging
Dim objDatapager As DataPager = TryCast(lvClientList.FindControl("dpClient"),DataPager)
objDatapager.SetPageProperties(e.StartRowIndex,e.MaximumRows,False)
lvClientList.DataSource = datatableOfClients
lvClientList.DataBind()
End Sub
我的问题是,如果用户选中一个复选框,然后点击下一页按钮,然后返回第一页,他选中的复选框将被取消选中。
我知道这是因为页面属性更改事件中的列表视图的 .DataBind() 因为它重新生成控件,但是有什么事情可以做以便我可以在用户返回第一页时保留并显示这些值?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。