04 January 2011

Enable Paging in repeater control

Page indexing in repeater

//declare PgNum as public integer

public int PgNum
{
get
{
if (ViewState["PgNum"] != null)
return Convert.ToInt32(ViewState["PgNum"]);
else
return 0;

}
set { ViewState["PgNum"] = value; }

}

// write below code where you are assigning the data source to the repeater

PagedDataSource pgds = new PagedDataSource();
pgds.DataSource = Rs//Assign data here which you want to assign to repeater, Here Rs is the list data source
pgds.AllowPaging = true;
pgds.PageSize = 4;
pgds.CurrentPageIndex = PgNum;

int PgCount = Rs.Count;
int vcnt = PgCount / pgds.PageSize;
if (PgNum < 1)
lnkPrev.Visible = false;
else if (PgNum > 0)
lnkPrev.Visible = true;

if (PgNum == vcnt)
lnkNxt.Visible = false;
else if (PgNum < vcnt)
lnkNxt.Visible = true;

rptPosts.DataSource = pgds;
rptPosts.DataBind();