Hi,
I have One DataGridView with 2 buttons Prev and Next.Here in my DataGridView I am using Paging Concept.I have 3 labels to show window no.(1,2..),records count(each page has 5 records only)and showing from to to.In the 1st page I am getting from to to(1-5) value when I click next page the result should as 6-10 and the 3rd page should show as 11-15.I didn't get the 2nd page result as shown above.
(Here my Database consists of 15 records in the Table)
Thanks in advance.
Loading

Rahul PrajapatPosted Aug 27, 2015, 7:02 AM
label3.Text = ((WindowNumber - 1) * RecordCount + 1).ToString() + " to " + (((WindowNumber - 1) * RecordCount ) + ds.Tables[0].Rows.Count).ToString();
Kanaparthi Sureshma ReddyPosted Aug 27, 2015, 6:51 AM
Rahul PrajapatPosted Aug 27, 2015, 3:32 AM
int RecordCount = 5;
private void loadGridView()
{
string str = "select * from Table1 where id >" + ((WindowNumber - 1) * RecordCount) + " and id <=" + (WindowNumber * RecordCount);
da = new SqlDataAdapter(str, con);
ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
label1.Text = WindowNumber.ToString();
label2.Text = RecordCount.ToString();
label3.Text = ((WindowNumber - 1) * RecordCount + 1).ToString() + " to " + (WindowNumber * RecordCount).ToString();
}
private void Form2_Load(object sender, EventArgs e)
{
loadGridView();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (WindowNumber < 3)
{
WindowNumber++;
loadGridView();
}
}
private void btnPrev_Click(object sender, EventArgs e)
{
if (WindowNumber > 1)
{
WindowNumber--;
loadGridView();
}
}