1。int aaa=yourdatagird.CurrentPageIndex;//你操作的叶
2。在重新帮定前yourdatagird.CurrentPageIndex=aa;
3。帮定
可以使用session,url等等方法

解决方案 »

  1.   

    谢谢你的回答,不过我的意思不是这样。新增的纪录我也不知道它到底在那页,除非用sql语句一遍一遍的算,我就是想有没有变通的方法可以能够解决这个问题。
      

  2.   

    还要判断你是否增加在页尾,如果是,则aaa=yourdatagrid.currentpageindex+1
      

  3.   

    InsertableDataGrid.aspx.vbImports System.Data
    Imports System.Data.SqlClientPublic Class InserTableDataGrid
      Inherits System.Web.UI.Page
      Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web Form Designer Generated Code "  'This call is required by the Web Form Designer.
      <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()  End Sub  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
      End Sub#End Region  Dim connstr As String = "Integrated Security=SSPI;User ID=sa;Initial Catalog=NorthWind;Data Source=.\netsdk"  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
          BindGrid()
        End If
      End Sub  Sub BindGrid()
        Dim cnn As New SqlConnection(connstr)
        Dim da As New SqlDataAdapter("select employeeid,lastname,firstname from employees", cnn)
        Dim ds As New DataSet()
        da.Fill(ds, "employees")    DataGrid1.DataSource = ds
        DataGrid1.DataBind()
      End Sub
      Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)_
       Handles DataGrid1.ItemCommand
        If e.CommandName = "Insert" Then
          Dim cnn As New SqlConnection(connstr)
          Dim t1 As TextBox = e.Item.FindControl("textbox2")
          Dim t2 As TextBox = e.Item.FindControl("textbox4")
          cnn.Open()
          Dim cmd As New SqlCommand("insert into employees(lastname,firstname) values('" & t1.Text & "','" & t2.Text & "')", cnn)
          cmd.ExecuteNonQuery()
          cnn.Close()
          BindGrid()
        End If
      End Sub
    End Class
      

  4.   

    谢谢大家热心的解答,可是不是我想要的答案。我就是想让在datagrid新增一行后能够在重定向的页面能看到它,但是这条记录由于在绑定后我也不知道它会在那一页出现,我就是想知道怎么能够定位到他再的那页,让用户能够马上看到他刚才新增的记录呢,或是有其他变通的方法更好了。