问题
I have a search page with parameters at the top and a search button with results at the bottom. The entire thing is wrapped in an update panel inside the master page. After clicking the search button it shows the first page. However if you click the next button on the DataPager it does not show the second page. It shows no results for the second page. Any help would be greatly appreciated.
回答1:
I think Nick has the right idea. It sounds like you are performing your search and populating your ListView in your OnClick method for your search button. You need to perform your search (or preferably cache the data the first time around) and bind that to the ListView for each new page that is requested using the DataPager.
You can do this fairly easily by creating a method for the ListView's OnPagePropertiesChanged event. Perform the search (or pull from the cache) and bind the ListView in that OnPagePropertiesChanged event and your data should populate. Your C# code might look like this:
protected void SearchButton_OnClick(object sender, EventArgs e)
{
PerformSearch();
}
protected void PerformSearch()
{
// ...Get your data.... //
ListView1.DataSource = data;
ListView1.DataBind();
}
protected void ListView1_OnPagePropertiesChanged(object sender, EventArgs e)
{
PerformSearch();
}
回答2:
It sounds like your control isn't binding in the postback, which event are you doing the DataBind() in, and is it under an
if(!IsPostBack) { }
wrapper of some sort?
回答3:
Please make sure that your page change event is registered with the Script Manager as it is out of the update panel control. ScriptManager.RegisterAsyncPostBackControl(DatePager Control);
回答4:
At the bottom of your update pannel do this:
<Triggers>
<asp:PostBackTrigger ControlID="DataPager1" />
</Triggers>
</asp:UpdatePanel>
回答5:
I had a similar problem when using a DataPager on a data control where EnableViewState=false.
来源:https://stackoverflow.com/questions/424705/how-do-i-get-the-asp-net-datapager-control-to-work-in-an-updatepanel