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

发布于 2024-07-11 15:05:46 字数 140 浏览 5 评论 0原文

我有一个顶部有参数的搜索页面,底部有一个带有结果的搜索按钮。 整个内容都包含在母版页内的更新面板中。 单击搜索按钮后,它会显示第一页。 但是,如果您单击 DataPager 上的下一个按钮,它不会显示第二页。 它没有显示第二页的结果。 任何帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

千鲤 2024-07-18 15:05:46

我认为尼克的想法是正确的。 听起来您正在执行搜索并在 OnClick 方法中为搜索按钮填充 ListView。 您需要执行搜索(或者最好在第一次缓存数据)并将其绑定到使用 DataPager 请求的每个新页面的 ListView。

您可以通过为 ListView 的 OnPagePropertiesChanged 事件创建一个方法来相当轻松地完成此操作。 执行搜索(或从缓存中提取)并在 OnPagePropertiesChanged 事件中绑定 ListView,并且您的数据应该会填充。 您的 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();
}

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();
}
山人契 2024-07-18 15:05:46

听起来您的控件没有在回发中绑定,您在哪个事件中执行 DataBind(),并且它是否在

某种if(!IsPostBack) { }

包装器下?

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?

烟酉 2024-07-18 15:05:46

请确保您的页面更改事件已在脚本管理器中注册,因为它不在更新面板控制范围内。
ScriptManager.RegisterAsyncPostBackControl(DatePager 控件);

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

三岁铭 2024-07-18 15:05:46

在更新面板的底部执行以下操作:

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

At the bottom of your update pannel do this:

       <Triggers>
                                <asp:PostBackTrigger ControlID="DataPager1" />
                            </Triggers>
                    </asp:UpdatePanel>
月寒剑心 2024-07-18 15:05:46

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

I had a similar problem when using a DataPager on a data control where EnableViewState=false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文