Paging in Datagridview

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlDataAdapter pagingAdapter;
DataSet pagingDS;
int scrollVal;

public Form1()
{
InitializeComponent();
scrollVal = 0;
}

private void button1_Click(object sender, EventArgs e)
{
string connectionString = “Data Source=.;Initial Catalog=pubs;Integrated Security=True”;
string sql = “SELECT * FROM Authors”;
SqlConnection connection = new SqlConnection(connectionString);
pagingAdapter = new SqlDataAdapter(sql, connection);
pagingDS = new DataSet();
connection.Open();
pagingAdapter.Fill(pagingDS, scrollVal, 5, “Authors_table”);
connection.Close();
dataGridView1.DataSource = pagingDS;
dataGridView1.DataMember = “Authors_table”;
}

private void button2_Click(object sender, EventArgs e)
{
scrollVal = scrollVal – 5;
if (scrollVal 23)
{
scrollVal = 18;
}
pagingDS.Clear();
pagingAdapter.Fill(pagingDS, scrollVal, 5, “authors_table”);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: