Wednesday, May 2, 2007

GridView Paging - MSDN Forums

GridView Paging - MSDN Forums: "GridView Paging "
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}

private DataTable getTable()
{
SqlConnection conn = new SqlConnection("Data source=localhost;user id=user;password=pass;database=ClassProject");
SqlDataAdapter adap = new SqlDataAdapter("Select * from lessons", conn);
DataTable dt = new DataTable();
adap.Fill(dt);
return dt;
}

private void bind()
{
DataTable dr = getTable();
GridView1.DataSource = dr;
GridView1.DataBind();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}

No comments: