Monday, September 7, 2009

Extending Gridview to implement partial paging



///
/// Extended Gridview that supports Custom Paging w/o using ObjectDataSource
/// - wfp May 30, 2008
///

public class CustomGridView : GridView
{
public CustomGridView() : base() { }

[Browsable(true), Category("RafnexProperties")]
[Description("Set the virtual item count for this gridview")]
[DefaultValue (-1)]
public int VirtualCount
{
get { return ViewState["virtualcount"]==null? -1 : (int)ViewState["virtualcount"]; }
set { ViewState["virtualcount"] = value; }
}

private int CurrentPageIndex
{
get
{
return ViewState["cur_pIndex"] == null ? 0 : (int)ViewState["cur_pIndex"];
}
set
{
ViewState["cur_pIndex"] = value;
}
}

public override object DataSource
{
get
{
return base.DataSource;
}
set
{
base.DataSource = value;
//save current page index, this.PageIndex value will be reset along the way(i dont know which event =P ) so we need to save it to be able to use it on InitializePager - wfp
this.CurrentPageIndex = this.PageIndex;
}
}

protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
{
if (this.AllowPaging)
{
pagedDataSource.AllowCustomPaging = true;
if (this.VirtualCount > -1) pagedDataSource.VirtualCount = this.VirtualCount;
pagedDataSource.CurrentPageIndex = this.CurrentPageIndex;
}

base.InitializePager(row, columnSpan, pagedDataSource);
}
}



Share/Save/Bookmark

No comments:

Post a Comment