简体   繁体   English

如何让ASP.NET DataPager控件在UpdatePanel中工作?

[英]How do I get the ASP.NET DataPager control to work in an UpdatePanel?

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. 但是,如果单击DataPager上的下一个按钮,则不会显示第二页。 It shows no results for the second page. 它显示第二页没有结果。 Any help would be greatly appreciated. 任何帮助将不胜感激。

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. 听起来您正在执行搜索并在OnClick方法中为搜索按钮填充ListView。 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. 您需要执行搜索(或者最好是第一次缓存数据),并将其绑定到使用DataPager请求的每个新页面的ListView。

You can do this fairly easily by creating a method for the ListView's OnPagePropertiesChanged event. 您可以通过为ListView的OnPagePropertiesChanged事件创建方法,相当容易地完成此操作。 Perform the search (or pull from the cache) and bind the ListView in that OnPagePropertiesChanged event and your data should populate. 执行搜索(或从缓存中拉出)并在该OnPagePropertiesChanged事件中绑定ListView,您的数据应该填充。 Your C# code might look like this: 您的C#代码可能如下所示:

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();
}

It sounds like your control isn't binding in the postback, which event are you doing the DataBind() in, and is it under an 听起来你的控件在回发中没有绑定,你正在做DataBind()的事件,它是在一个

if(!IsPostBack) { }

wrapper of some sort? 某种包装?

当在EnableViewState=false的数据控件上使用DataPager时,我遇到了类似的问题。

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); ScriptManager.RegisterAsyncPostBackControl(DatePager Control);

At the bottom of your update pannel do this: 在更新底部的底部执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM