How to make ASP.NET DataPager control work in UpdatePanel?

I have a search page with options at the top and a search button with results below. All this is wrapped in the update panel inside the main page. After clicking the search button, the first page is displayed. However, if you click the next button on the DataPager, it will not display the second page. It does not show results for the second page. Any help would be greatly appreciated.

+3
source share
5 answers

I think Nick has the right idea. It looks like you are doing a search and populating the ListView in the OnClick method for your search button. You need to search (or, preferably, cache the data for the first time) and associate it with a ListView for each new page that is requested using the DataPager.

You can do this quite easily by creating a method for the ListView OnPagePropertiesChanged event. Perform a search (or pull from the cache) and bind the ListView in this OnPagePropertiesChanged event and your data should fill. 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();
}
+3
source

It seems like your control is not required to postback what event you are doing in the DataBind (), and whether it is under

if(!IsPostBack) { }

any shell?

+1
source

Please make sure that your page change event is logged in the Script Manager, as it is located outside the update control panel item. ScriptManager.RegisterAsyncPostBackControl (DatePager Control);

0
source

At the bottom of the update window, do the following:

       <Triggers>
                                <asp:PostBackTrigger ControlID="DataPager1" />
                            </Triggers>
                    </asp:UpdatePanel>
0
source

I had a similar problem when using DataPagerto manage data where EnableViewState=false.

0
source

All Articles