我有一个与ListView一起使用的DataPager控件,当页面加载时,页面导航将显示第一个、下一个、最后一个、上一个和10个页面,但是当我单击页面的任何按钮或超链接时,无论我单击多少次,都不会发生任何事情。我听说你必须在preredender中做一些事情,但还没有看到任何关于这是如何工作的代码。谁能告诉我我应该在prerender中放入什么代码(以及如何调用prerender),如果这是解决方案,如果不是如何让我的datapager工作?
<asp:UpdatePanel ID="upSearchResults" runat="server">
<ContentTemplate>
<asp:Label ID="lblErrorMSG" CssClass="ErrorText" runat="server" />
<asp:Panel ID="plSearchResults" runat="server">
<table style="width: 100%" border="1">
<tr>
<td>
<asp:Literal ID="lblTitleRow" runat="server" />
</td>
<td>
<asp:Literal ID="lblDescriptionRow" runat="server" />
</td>
<td class="TableSelectButton">
<asp:Button ID="btnAddNewItem" Text="Select" runat="server" />
</td>
</tr>
<asp:ListView ID="lvSearchResults" runat="server">
<LayoutTemplate>
<tr id="itemPlaceHolder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("Title")%>
</td>
<td>
<%#Eval("Descript")%>
</td>
<td class="TableSelectButton">
<asp:Button ID="btnEditItem" Text="Select" PostBackUrl='<%#String.Format("{0}.aspx?ID={1}&SectionID={2}", Eval("PageName"), Eval("ID"), ddlMediaTitle.SelectedValue.ToString())%>' runat="server" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
</asp:Panel>
<div class="Center">
<asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
发布于 2012-09-11 03:33:23
通过做两件事,我能够让你的代码样本正常工作。首先,在列表视图控件中,我添加了OnPagePropertiesChanged事件,并再次绑定数据。
<asp:ListView ID="lvSearchResults" runat="server"
OnPagePropertiesChanged="lvSearchResults_PagePropertiesChanged">
在后面的代码中:
protected void lvSearchResults_PagePropertiesChanged(object sender, EventArgs e)
{
//bind the lvSearchResults
}
为了让更新面板正常工作,我使用了这个触发器:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lvSearchResults"
EventName="PagePropertiesChanged" />
</Triggers>
我有一个建议,就是在你完成所有的工作后,添加更新面板。它们似乎隐藏了许多问题,并使它们更难解决。
享受吧!
发布于 2012-09-11 02:18:06
我非常确定列表视图控件是已知的控件之一,不能在更新面板控件中使用。通过临时删除更新面板标记来测试这一点。
发布于 2012-09-11 03:25:50
如果列表视图数据是用plSearchResults.DataSource =.?编程填充的。,因此它被称为页面中的每个回发...包括异步的。
并且DataSource对象必须实现了分页器回调。
所以你的解决方案。(如果我假设正确)是:在代码中添加一行代码,如下所示。
if(!isPostBack) //This line will assure tha the binding will be filled just once
plSearchResults.DataSource = .???.
那么它将不会重新绑定每个回发...确保分页的回调是在DataSource对象上实现的
Asp.NET数据源对象,如SQLDataSource、LinqDataSource、EntitiesDataSource……它们都实现了分页。如果要以编程方式创建一个数据源,则必须实现分页回调。
https://stackoverflow.com/questions/12361663
复制相似问题