本文介绍了如何在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

推荐答案

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中区分页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:57