【问题标题】:Is it possible to get selected index page of DetailsView control in Page_Load method?是否可以在 Page_Load 方法中获取 DetailsView 控件的选定索引页?
【发布时间】:2016-01-26 23:53:07
【问题描述】:

我有 DetailsView 控件,启用了分页。

当我在 DetailsView 控件中选择另一个页面时,会产生回发并触发 Page_Load 方法。

我需要获取选中的索引页面。

知道如何在 Page_Load 方法中获取 DetailsView 控件的选定索引页吗?

【问题讨论】:

  • 你能分享一点源代码吗?这可能会有所帮助。

标签: c# asp.net


【解决方案1】:

我知道的唯一方法是检查您的 Page_load 中的表单帖子。像这样:

if (Request.Form["__EVENTTARGET"] == detailsView1.UniqueID)
{
    int reqPage;
    if (int.TryParse(Request.Form["__EVENTARGUMENT"].Replace("Page$", string.Empty), out reqPage))
    {
        // do something with that requested page, but remember to -1
    }
}

【讨论】:

  • 能否请您简单解释一下为什么我会进入 Request.Form["__EVENTARGUMENT"] this: Page$+someIndex Page$ 是什么意思?
  • 这是 ASP 唯一标识页码的方式。我假设这只是一个设计决定。
【解决方案2】:

看看 ASP.NET 页面生命周期: https://msdn.microsoft.com/en-us/library/ms178472.aspx

回发事件在 PageLoad 之后处理。我会订阅

DetailsView.PageIndexChanging 

事件:

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.pageindexchanging(v=vs.110).aspx

【讨论】:

  • 我需要在 Page_load 方法中获取索引
猜你喜欢
  • 1970-01-01
  • 2010-12-22
  • 1970-01-01
  • 1970-01-01
  • 2012-11-05
  • 2020-09-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-22
相关资源
最近更新 更多