使用分页时访问 gridview 上的控件

发布于 2024-11-29 02:16:02 字数 1152 浏览 0 评论 0原文

我正在尝试从具有多个页面的 gridview 上的复选框获取回发信息。当只有一页数据时,一切正常,但如果您移动到不同页面,无论您在哪一页,分页复选框总是返回 false。例如,在我的应用程序中,我单击了第 2 页链接并选择了该页面上的复选框,然后发回。在我的处理程序中,我迭代每一行并像这样检查。

 For Each row In grdView.Rows
         Dim RowCheckBox As CheckBox = CType(row.FindControl(crtl), CheckBox)
        If RowCheckBox.Checked Then
            sSelectedItem = CType(row.FindControl(sIDFieldName), TextBox).Text
            checkedItems.Add(sSelectedItem)
        End If
 Next

所以我想要的信息在第 2 页的第一行(第 6 行)。但没有一个复选框报告被选中。以下是我的 gridview 报告的内容:

? grdView.Rows.Count 5 
? grdView.PageCount 2 
? grdView.PageSize 5

因此,即使它知道每页 5 行和 2 页,它也不会看到超过 5 行。它还将 pageindex 报告为 0(第一页) 如果我将 PageIndex 设置为 1(第二页),则 grdView.Rows.Count = 5,即使第二页上只有 1 行。

尽管将页码设置为第二页,但我也获得了与第一页相同的返回值。我不知道如何在第一个页面之外的页面上获取任何内容。

我用谷歌搜索了这个,令人惊讶的是没有找到答案,因为这似乎是常用来获取数据的东西。 这是 C# 部分中一个未解答问题的重新发布,但我认为也许可以通过新帖子找到答案。

我查看了复选框字段,发现编号问题。例如,在第 2 页上有一行,复选框的 ID 为 ....$ctl02$... 但是当您在循环中查询复选框时,它给出的 UniqueID 为 ....$ctl11$...很明显他们返回的是 false。但是,如果您使用页面中显示的 ID 执行 Request.Item,您将获得复选框。使用 UniqueID,复选框会返回,您什么也得不到,因此所有复选框的选中属性都是 false。

任何帮助将不胜感激。

I am attempting to get information at postback from a checkbox on a gridview that has multiple pages. Things work fine when there is only one page worth of data, but with paging checkboxes always return false no matter what page you are on if you move to different pages. So for example in my app I have clicked on the page 2 link and selected a checkbox on that page and then posted back. In my handler I iterate through every row and check like this.

 For Each row In grdView.Rows
         Dim RowCheckBox As CheckBox = CType(row.FindControl(crtl), CheckBox)
        If RowCheckBox.Checked Then
            sSelectedItem = CType(row.FindControl(sIDFieldName), TextBox).Text
            checkedItems.Add(sSelectedItem)
        End If
 Next

So the information I want is on the 1st row of page 2 (row 6). But none of the checkboxes report being checked. Here is what my gridview is reporting:

? grdView.Rows.Count 5 
? grdView.PageCount 2 
? grdView.PageSize 5

So even though it knows there are 5 rows per page and 2 pages it does not see more that 5 rows. It also reports the pageindex as 0 (1st page) If I set the PageIndex to 1 (second page) the grdView.Rows.Count = 5 even though there is only 1 row on the second page.

I also get the same return value as the first page despite setting the page number to the second page. I can not figure out how to get anything on a page other than the first one.

I have googled this and suprisingly have not found an answer since this seems to be somthing that would be commonly used to get data.
This is a repost of an unanswered question in the C# section, but I thought maybe an answer could be found with a fresh post.

I looked at the checkbox fields and found numbering problems. For instance on page 2 there is one row and the checkbox has a ID of ....$ctl02$... But when you query the checkbox in a loop it gives it's UniqueID as ....$ctl11$... So obviously they are returning false. But if you do a Request.Item with the ID that shows in the page you get the checkbox. With the UniqueID the checkbox spits back you get nothing and hence all the checkboxes' checked properties are false.

Any help would be appreciated.

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

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

发布评论

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

评论(1

傲鸠 2024-12-06 02:16:02

当您最初将数据设置到 GridView 时,您可能会执行以下操作:

grid.DataSource = something
grid.DataBind()

当您进行数据绑定时,当前页面的数据将绑定到网格,仅此而已。
如果要从其他页面访问数据,则需要重置数据源,并重新绑定数据。

仅将当前页设置为 2 没有帮助,因为第二页的数据从未绑定到网格。

When you initially set the data to the GridView, you probably did something like this:

grid.DataSource = something
grid.DataBind()

When you databind, the current page worth of data is bound to the grid, nothing more.
If you want to access data from another page, you need to reset the datasource, and rebind the data.

Just setting the current page to 2 won't help, because the second page worth of data was never bound to the grid.

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