ADO/ADO.NET - when clicking on next/previous button next/previous record shd display

Asked By pragati ganga on 21-Jan-12 01:42 AM
Hi,
I have a application where the page will load the latest record from database based on division id (grouping by division id)  which will get by selecting from the dropdownlist...when select from dropdown list the latest record of that selection will display.
i have previous and next button on d page when click on next or previous button the next or previous record should display based on the division id(selection).....im getting the latest record from db but i dont know how to get th next/previous records based on that.....
how can i achieve this?

Thanks
D Company replied to pragati ganga on 21-Jan-12 01:49 AM
Hello Pragati,

On click of next and previous button you have to bind the data again, or simple you can call bind data which you have already defined for the page load or on selection of dropdown item

Regards
D

dipa ahuja replied to pragati ganga on 21-Jan-12 02:58 AM
 
 
string conn = "ConnectionString";
SqlDataAdapter da;
DataSet ds;
SqlCommand comm;
 
private void Form1_Load(object sender, EventArgs e)
{
  //load data in textboxes
  fillData();
}
 
 
void fillData()
{
  //fill data on page load
  da = new SqlDataAdapter("select * from emp", conn);
  ds = new DataSet();
  da.Fill(ds);
 
  textBox1.Text = ds.Tables[0].Rows[0][0].ToString();
  textBox2.Text = ds.Tables[0].Rows[0][1].ToString();
}
//method to load data in textbox
void show(int i)
{
  textBox1.Text = ds.Tables[0].Rows[i][0].ToString();
  textBox2.Text = ds.Tables[0].Rows[i][1].ToString();
}    
private void BtnLast_Click_1(object sender, EventArgs e)
{
  //display last record
  show(ds.Tables[0].Rows.Count - 1);
}
 
private void BtnFirst_Click_1(object sender, EventArgs e)
{
  //display first record
  show(0);
}
 
private void btnPrev_Click(object sender, EventArgs e)
{
  //previous record
    int c = Convert.ToInt32(ds.Tables[0].Rows.Count.ToString());
 
  if ((BindingContext[ds.Tables[0]].Position) == 0)
  {
    MessageBox.Show("Begin of Records Reached!!");
 
  }
  else
  {
    int i = BindingContext[ds.Tables[0]].Position -= 1;
    BindingContext[ds.Tables[0]].Position = i;
    show(i);
  }         
}
private void btnNext_Click(object sender, EventArgs e)
{
  //next Record
  int c = Convert.ToInt32(ds.Tables[0].Rows.Count.ToString());
 
  if ((BindingContext[ds.Tables[0]].Position) == c - 1)
  {
    MessageBox.Show("End of Records Reached!!");
  }
  else
  {
    int i = BindingContext[ds.Tables[0]].Position += 1;
    BindingContext[ds.Tables[0]].Position = i;
    show(i);
  }
}
}
 
pragati ganga replied to dipa ahuja on 21-Jan-12 06:15 AM
Thanks for the reply.....
But my query is selecting items grouped by division id ans the latest record from that criteria will show in page load.....later when click previous/next button it should display the previous/next record from that criteria
pragati ganga replied to dipa ahuja on 23-Jan-12 07:24 AM
I tried this one but im getting error like

 'System.Windows.Forms.BindingContext' is a 'type' but is used like a 'variable'