I recommend you to bind the textbox controls to columns
of your table inside your dataset, then get the
bindingmanagerbase for the table, then use the position
property of the bindingmanagerbase to navigate previous
and next.
Rogelio Moreno
-----Original Message-----
I need a little help to be able to use a Next and Previous button toget the next record or the previous record to Textboxes instead of adatagird. I am using a stored procedure to get the data I want fromthe SQL Server 2000 database. And I can get it into the textboxes.Sometimes there will be multiple records in the dataset but I can onlyget the first record in the textboxes, thus the need to have the Nextand Previous record button. Any help will be appreacted. I am alsoputting some of my code here to give you a idea of what I am doing. Itis all hardcoded.
Thanks
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnSearch.Click
If txtLastName.Text <> "" Then
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter
'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server= (local);database=dsgtest;Trusted_Connection=yes")
'Create a DataAdapter, and then provide the name of the storedprocedure.
MyDataAdapter = New SqlDataAdapter("LastName", MyConnection)
'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
'Create and add a parameter to Parameters collection for the storedprocedure.
MyDataAdapter.SelectCommand.Parameters.Add(New
SqlParameter("@em_lName", _
SqlDbType.VarChar, 40))
'Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters ("@em_lname").Value =Trim(txtLastName.Text)
'Create and add an output parameter to Parameters collection.MyDataAdapter.SelectCommand.Parameters.Add(New
SqlParameter("@RowCount", _
SqlDbType.Int, 4))
'Set the direction for the parameter. This parameter returns the Rowsreturned.
MyDataAdapter.SelectCommand.Parameters ("@RowCount").Direction =ParameterDirection.Output
DS = New DataSet() 'Create a new DataSet to hold the records.MyDataAdapter.Fill(DS, "dsLastName") 'Fill the DataSet with the rowsreturned.
' Get the number of rows returned, and then assign it to the Labelcontrol.
'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " RowsFound!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters (1).Value & "Records Found for Last Name of " & txtLastName.Text & " search!"
'Set the data source for the DataGrid as the DataSet that holds therows.
'dgGrid.DataSource = DS.Tables("dsLastName").DefaultView
Dim lname = DataBinder.Eval(DS,
"Tables(0).defaultview.(0).lastname").ToString( )
Dim fname = DataBinder.Eval(DS,
"Tables(0).defaultview.(0).firstname").ToString ()
Dim pnumber = DataBinder.Eval(DS,
"Tables(0).defaultview.(0).phone").ToString()
TextBox1.Text = lname
TextBox2.Text = fname
TextBox3.Text = pnumber
Label1.Text = fname + " " + lname + " Phone Number " + pnumber
MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.
End If
End Sub
Private Sub btnPrev_Command(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.CommandEventArgs) Handles btnPrev.Command
End Sub
Private Sub btnNext_Command(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.CommandEventArgs) Handles btnNext.Command
End Sub
End Class
.