在网格视图中分页时如何计算总行数

时间:2013-09-05 11:05:16

标签: asp.net

我正在使用网格视图来启用pageindexchaning和pageindexchanged我只是在1,2,3,4,5处输入了一些值,在20页中,它在添加时有一些文本框值是从总页数中只有一页.. 但我需要阅读所有页面行我需要你的帮助.. 在页面加载时我写了这段代码..

    Dim sname As String = Session("Current_user")

    If (TextBox3.Text <> "") Then
        TextBox3.Text = ""
    End If
    Button1.BackColor = Drawing.Color.White

    Dim con As connect_comp = New connect_comp()
    ocompany = CType(HttpContext.Current.Session("company"), SAPbobsCOM.Company)
    'Dim myConnection As SqlConnection
    'Dim ConfigStr As String = ConfigurationManager.ConnectionStrings("PayrollConnectionString").ConnectionString
    'myConnection = New SqlConnection(ConfigStr)
    'myConnection.Open()

    Dim RS1 As SAPbobsCOM.Recordset
    RS1 = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
    RS1.DoQuery("select t1.U_ItmCde,t1.U_ItmDes,t1.U_ItmNme,t1.U_UOM    from  [@TI_VITHDR] t0 inner join  [@TI_VITLNE] t1 on  t0.Code =t1.Code  where t0.U_Whse='" & sname & "'")


    Dim dt As New DataTable()
    Dim dr As DataRow = Nothing
    dt.Columns.Add(New DataColumn("SNO", GetType(String)))
    dt.Columns.Add(New DataColumn("ItemName", GetType(String)))
    dt.Columns.Add(New DataColumn("ItemCode", GetType(String)))
    dt.Columns.Add(New DataColumn("Item Description", GetType(String)))
    dt.Columns.Add(New DataColumn("UOM", GetType(String)))

    For i As Integer = 1 To RS1.RecordCount
        dr = dt.NewRow()

        dr("SNO") = i
        dr("ItemName") = RS1.Fields.Item("U_ItmDes").Value
        dr("ItemCode") = RS1.Fields.Item("U_ItmCde").Value
        dr("Item Description") = RS1.Fields.Item("U_ItmNme").Value
        dr("UOM") = RS1.Fields.Item("U_UOM").Value
        dt.Rows.Add(dr)
        RS1.MoveNext()
    Next


    ViewState("CurrentTable") = dt
    Gridview1.DataSource = dt
    Gridview1.DataBind()

-------------------------
page index and page index changed i have written 
Protected Sub Gridview1_PageIndexChanging(ByVal sender As Object, ByVal e As    GridViewPageEventArgs)
    'Session("Test") = Gridview1
    'Gridview1 = Nothing
    'Gridview1.PageIndex = e.NewPageIndex
    'SetInitialRow()
    Response.Write(Gridview1.PageIndex.ToString())
    Dim d As Integer = Gridview1.PageCount
    Dim texts As String() = New String(Gridview1.PageSize - 1) {}
    Dim texts1 As String() = New String(Gridview1.PageSize - 1) {}
    Dim textBox, textBox1 As TextBox
    Dim count As Integer = 0
    For Each row As GridViewRow In Gridview1.Rows
        textBox = DirectCast(row.FindControl("TextBox1"), TextBox)
        textBox1 = DirectCast(row.FindControl("TextBox2"), TextBox)
        If textBox IsNot Nothing Then
            texts(count) = textBox.Text
        Else
            texts(count) = ""
        End If


        If textBox1 IsNot Nothing Then
            texts1(count) = textBox1.Text
        Else
            texts1(count) = ""
        End If
        count += 1

    Next
    Session("page" + Gridview1.PageIndex.ToString()) = texts
    Session("page1" + Gridview1.PageIndex.ToString()) = texts1
    Gridview1.PageIndex = e.NewPageIndex
    SetInitialRow()
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    If Session("page" + Gridview1.PageIndex.ToString) IsNot Nothing Then
        Dim textBox As TextBox
        Dim texts As String() = DirectCast(Session("page" + Gridview1.PageIndex.ToString()), String())
        For i As Integer = 0 To Gridview1.Rows.Count - 1
            textBox = DirectCast(Gridview1.Rows(i).FindControl("TextBox1"), TextBox)
            textBox.Text = texts(i)
        Next
    End If

    If Session("page1" + Gridview1.PageIndex.ToString) IsNot Nothing Then
        Dim textBox1 As TextBox
        Dim texts1 As String() = DirectCast(Session("page1" + Gridview1.PageIndex.ToString()), String())
        For i As Integer = 0 To Gridview1.Rows.Count - 1
            textBox1 = DirectCast(Gridview1.Rows(i).FindControl("TextBox2"), TextBox)
            textBox1.Text = texts1(i)
        Next
    End If
End Sub
----------

虽然我正在计算      尝试             Dim Cnt1,Rowcnt1 As Integer             Rowcnt1 = Gridview1.Rows.Count             对于Cnt1 = 0 To Rowcnt1 - 1

这里我遇到的问题是它只读取一个页面值我需要整个网格行。  任何身体都可以给我一些建议......

1 个答案:

答案 0 :(得分:0)

当您使用SQL并查询数据库时,您的总行数=

select Count(*) from  [@TI_VITHDR] t0 inner join  [@TI_VITLNE] t1 on  t0.Code =t1.Code  where t0.U_Whse='" & sname & "'"