How to Page a DataGrid

A

anonieko

Assuming that paging is enable. The most common mistake are:
1. Forgetting to check for postback. Use IsPostBack propert of page.
2. Forgetting to code PageIndexChanged event .
3. *Important* Not putting the correct order of statements in that
event. First, set the CurrentPageIndex . Then, bind.





private void Page_Load(object sender, System.EventArgs e)
{
if ( !Page.IsPostBack )
{
BindGrid();
}
}


private void DataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}

private void BindGrid()
{
oracleDataAdapter1.Fill(groupDS1);
DataGrid1.DataSource = groupDS1.Tables[0].DefaultView;
DataGrid1.DataBind();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top