Public Class WebForm1
    Inherits System.Web.UI.Page
    Private CurrentPage As Integer
    Private TestInt As Integer = 0
    Private Sub ltbnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ltbnext.Click        TestInt += TestInt
        TextBox4.Text = TestInt.ToString
    End Sub
End Class刚刚的那个粘错了,应该是这样的,在这样的情况下,testInt没有改变;

解决方案 »

  1.   

    因为页面每次刷新时又变为0了,试试用ViewState["TestInt"] = Convert.ToInt32(ViewState["TestInt"]) + 1
      

  2.   

    ViewState("TestInt") = Convert.ToInt32(ViewState("TestInt")) + 1
    这个还是不行啊;
      

  3.   

    Public Class WebForm1
        Inherits System.Web.UI.Page
        Private CurrentPage As Integer
        Private TestInt As Integer'..............    Private Sub FillGrid(ByVal currentSQLCommand As SqlClient.SqlCommand)
            Dim dr As SqlClient.SqlDataReader
            'SqlConnection1.ConnectionString.us
            SqlConnection1.Open()
            dr = currentSQLCommand.ExecuteReader
            DataGrid1.DataSource = dr
            DataGrid1.DataBind()
            dr.Close()
            SqlConnection1.Close()        ViewState("Currentpage") = CurrentPage
            If DataGrid1.Items.Count < DataGrid1.PageSize Then
                ltbnext.Enabled = False
            End If
        End Sub    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            If Not Page.IsPostBack Then
                cmdNext.Parameters("@customerid").Value = ""
                CurrentPage = 0
                FillGrid(cmdNext)
            End If
        End Sub
        Private Sub ltbnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ltbnext.Click
            CurrentPage = CType(ViewState("CurrentPage"), Integer)
            CurrentPage = CurrentPage + 1
            Dim LastID As String = DataGrid1.Items(9).Cells(0).Text
            cmdNext.Parameters("@customerid").Value = LastID
            FillGrid(cmdNext)
        End Sub    Private Sub lbtPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtPrevious.Click
            ltbnext.Enabled = True
            CurrentPage = CType(ViewState("CurrentPage"), Integer)
            CurrentPage -= 1
            If CurrentPage >= 0 Then
                Dim PriverousID As String = CType(ViewState((CurrentPage).ToString), String)
                cmdPrevious.Parameters("@customerid").Value = PriverousID
                FillGrid(cmdPrevious)
            End If
        End Sub
    End Class
    这是MSDN里边的,但是,我运行起来,也是每次取的CurrentPage都会初始。为什么叱?那儿没有设置吗?
      

  4.   

    要asp.net Webform中,象楼主的情况,最好的解决方案就是将每次产生的TestInt的值保存在ViewState中,因为这个值只在当前页面有效,没必要存在Session中。