Scott G

Scott G

  • NA
  • 103
  • 7.1k

coding a Next button to advance to next row of data table

Oct 16 2018 2:57 PM
I have a form with two panels. A button click makes my second panel visible which has several textboxes bound to a database through the use of a DataTable and SqlDataAdapter.
private void btnViewAgents_Click(object sender, EventArgs e)
{
pnlAgents.Visible = true;
SqlCommand SelAgts = new SqlCommand("SELECT * FROM myTable ORDER BY last_name", misc);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(SelAgts);
da.Fill(dt);
misc.Open();
txtLName.Text = dt.Rows[0]["last_Name"].ToString();
txtFName.Text = dt.Rows[0]["first_name_mi"].ToString();
txtAgt.Text = dt.Rows[0]["agency_use"].ToString().Substring(0, 5);
txtStore.Text = dt.Rows[0]["agency_use"].ToString().Substring(6, 19);
...
...
misc.Close();
}
I now have two other buttons on this panel, next and previous that I need to have move to the next or previous row in the table. So basically on the next button click I need each textbox to advance from row 0 to 1 and so on with each click.

Answers (5)