我正在使用网格视图来启用 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 For Cnt1 = 0 To Rowcnt1 - 1
在这里我得到了问题,它只读取一页值我需要整个网格行。任何人都可以给我一些建议..