Tuesday, October 28, 2008

PagerRow not showing in SPGridView when setting AllowPaging=true

When you enable paging in an SPGridView, the PagerRow doesn't show up by default. To work around this, you have to set the PagerTemplate to 'null' AFTER adding the control to the controls collection but BEFORE calling DataBind().

e.g.

protected override void CreateChildControls() {
SPGridView grid = new SPGridView;
grid.AllowPaging=true;
this.Controls.Add(grid);
//set PagerTemplate to null
grid.PagerTemplate = null;
grid.PageIndexChanging +=
new GridViewPageEventHandler(grid_PageIndexChanging);
grid.DataBind();
}

No comments:

Post a Comment