如何在gridview中区分页面 [英] How to make difference between pages in gridview

查看:76
本文介绍了如何在gridview中区分页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是当我检查gridview第一页的第一行时,下一页的第一行自动检查第一行,



我制作这些子和我在_PageIndexChanging中调用它



我尝试过:



I mean when i checked the first row in the first page in gridview the first row in the next page the first row checked automatically ,,,

I make these sub and i call it in _PageIndexChanging

What I have tried:

Protected Sub CHECK1()
        'Dim n As String
        Dim dt As DataTable = Session("LoadData")
        For x = 0 To GridNatRel.Rows.Count - 1
            If dt.Rows(x).Item("check1") = 1 Then
                CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = True
            Else
                CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = False
            End If
        Next

    End Sub
    Protected Sub CHECK2()
        Dim rowIndex As Integer = Nothing
        Dim DT As DataTable = Session("LoadData")
        For i = 0 To GridNatRel.Rows.Count - 1
            If CType(GridNatRel.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = True Then
                DT.Rows(i).Item("check1") = 1
            Else
                DT.Rows(i + rowIndex).Item("check1") = 0
            End If
        Next
    End Sub

推荐答案

您需要映射 GridView中行的索引 DataTable 中等效行的索引。您可以使用 GridView PageIndex PageSize 属性这样做。

You need to map the index of the row in the GridView to the index of the equivalent row in the DataTable. You can use the GridView's PageIndex and PageSize properties to do that.
Protected Sub CHECK1()
    Dim dt As DataTable = Session("LoadData")
    Dim startIndex As Integer = GridNatRel.PageIndex * GridNatRel.PageSize
    For x = 0 To GridNatRel.Rows.Count - 1
        If dt.Rows(startIndex + x).Item("check1") = 1 Then
            CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = True
        Else
            CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked = False
        End If
    Next
End Sub

Protected Sub CHECK2()
    Dim dt As DataTable = Session("LoadData")
    Dim startIndex As Integer = GridNatRel.PageIndex * GridNatRel.PageSize
    For x = 0 To GridNatRel.Rows.Count - 1
        If CType(GridNatRel.Rows(x).FindControl("CheckBox1"), CheckBox).Checked Then
            dt.Rows(startIndex + x).Item("check1") = 1
        Else
            dt.Rows(startIndex + x).Item("check1") = 0
        End If
    Next
End Sub



应该在 PageIndexChanging 事件中调用 CHECK2 方法;需要在 DataBound 事件中调用 CHECK1 方法。


The CHECK2 method should be called in the PageIndexChanging event; the CHECK1 method needs to be called in the DataBound event.


这篇关于如何在gridview中区分页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆