而在asp.net中分页如何在网格中保存文本框值

时间:2013-09-04 07:51:20

标签: asp.net

嗨我的问题是在页面加载后的网格视图中我在文本框中输入了一些值但是在按下一页后页面值正在消失.. 如何将值保存并检索到网格视图中.. 我可以将它保存在会话中,但我怎样才能将其保存到当前页面中。

这是我的代码我可以将其保存到值中但是 在更改其他页面后再次进入同一页面后,如何将值传递到相应的页面中..

Protected Sub Gridview1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
    'Gridview1.PageIndex = e.NewPageIndex
    'SetInitialRow()

    Dim pageindex As Integer = Gridview1.PageIndex

    Response.Write(Gridview1.PageIndex.ToString())
    Dim d As Integer = Gridview1.PageCount
    Dim texts As String() = New String(Gridview1.PageSize - 1) {}
    Dim textBox As TextBox
    Dim count As Integer = 0

    For Each row As GridViewRow In Gridview1.Rows
        textBox = DirectCast(row.FindControl("TextBox1"), TextBox)
        If textBox IsNot Nothing Then
            texts(count) = textBox.Text
        Else
            texts(count) = ""
        End If
        count += 1
    Next

    Session("one" + "pageindex") = texts
    Gridview1.PageIndex= e.NewPageIndex
    SetInitialRow()

    'Dim sessionint As Integer = Session("page" + "pageindex")
    'If Session("page" + "pageindex") IsNot Nothing Then
    '    Dim textBox1 As TextBox
    '    Dim texts1 As String() = DirectCast(Session("page" + "pageindex"), String())
    '    For i As Integer = 0 To Gridview1.Rows.Count - 1
    '        textBox1 = DirectCast(Gridview1.Rows(i).FindControl("textbox"), TextBox)
    '        textBox1.Text = texts(i)
    '    Next
    'End If
End Sub

1 个答案:

答案 0 :(得分:0)

要绑定到gridview的数据源是什么?

这是我一直在做的两种方式......

  • 抓取整个数据表并将其放入 ViewState(“dataTable”)。从那里过滤行和数据。

每当您按“下一页”时,将行更新为 ViewState(“dataTable”)

然后使用ViewState(“dataTable”)重新绑定gridview。

  • 按“下一页”时直接更新数据库。