Search This Blog

Friday, December 02, 2005

DataGrid Pagination in Webparts

Today I had an issue with a data grid on a web part not paginating. After a bit of merry-go-around the web I could figure out how to do it.

The following is the sequence of steps.

Step 1: Set up your CreateChildControls

protected override void CreateChildControls()
dGrid = new DataGrid();
// write code to set up the data grid
// with your columns etc.

dGrid .PageIndexChanged +=new DataGridPageChangedEventHandler(dGrid _PageIndexChanged);


Step 2: Create the PageIndexChanged Event handler
private void dGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e )
dGrid .CurrentPageIndex = e.NewPageIndex;
dGrid.DataSource = dtSource;

Step 3: Render the DataGrid

protected override void RenderWebPart(HtmlTextWriter output)

You should be in business. Happy coding guys.

No comments: