i have to get the first,previous,next,last records on clicking of subsequent buttons.I m using textboxes for displaying the values of the record.But i am unable to move to the next,previous,last records as by default 1st record is displayed.Any help please
private void Form1_Load(object sender, EventArgs e)
{
binddata();
editdata();
}
//code for filling the gridview
public void binddata()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from cities", sqlcon);
da.Fill(ds,
"fill");
dataGridView1.DataSource = ds.Tables[0];
}
public
void editdata()
{
//code for editing the data to the textboxes on click of row in datagridview
Object no = dataGridView1.CurrentRow.Cells[1].Value;
SqlDataAdapter da3 = new SqlDataAdapter("select * from cities where number= " + no + "", sqlcon);
da3.TableMappings.Add(
"Table", "edit");
da3.Fill(ds3);
if (ds3.Tables["edit"].Rows.Count > 0)
{
txtno.DataBindings.Add(
"Text", ds3, "edit.number");
txtcity.DataBindings.Add(
"Text", ds3, "edit.city");
}
}
private
void btnfirst_Click(object sender, EventArgs e)
{
this.BindingContext[ds3, "edit"].Position = 0;
}
private void btnprevious_Click(object sender, EventArgs e)
{
this.BindingContext[ds3, "edit"].Position =
(
this.BindingContext[ds3, "edit"].Position - 1);
}
private void btnnext_Click(object sender, EventArgs e)
{
this.BindingContext[ds3, "edit"].Position =
(
this.BindingContext[ds3, "edit"].Position + 1);
}
private void btnlast_Click(object sender, EventArgs e)
{
this.BindingContext[ds3, "edit"].Position =
(
this.BindingContext[ds3, "edit"].Count - 1);
}