Devendra  Kumar

Devendra Kumar

  • NA
  • 517
  • 246.3k

Dynamic Paging For DataList Control with PagedDataSource

Feb 23 2016 1:29 AM
Dynamic Paging For DataList Control with PagedDataSource
show paging like this:
 
 pre  1,2,3,..... next 
my code..
 
PagedDataSource pgd = new PagedDataSource();
objAdmin.OperationName = "SelectAll";
pgd.DataSource = ds1.Tables[0].DefaultView;
pgd.CurrentPageIndex = CurrentPageIndex;
pgd.AllowPaging = true;
pgd.PageSize = 20;
Next.Enabled = !(pgd.IsLastPage);
Prev.Enabled = !(pgd.IsFirstPage);
prev1.Enabled = !(pgd.IsFirstPage);
next1.Enabled = !(pgd.IsLastPage);
DataTable dtable = new DataTable();
dtable.Columns.Add("PageIndex");
dtable.Columns.Add("PageText");
for (i =0; i < pgd.PageCount ;i++ )
{
DataRow dr = dtable.NewRow();
dr[0] = i;
dr[1] = i + 1;
dtable.Rows.Add(dr);
}
DataListPaging1.DataSource = dtable;
DataListPaging1.DataBind();
DataTable dt = new DataTable();
dt.Columns.Add("PageIndex2");
dt.Columns.Add("PageText2");
for (i = 0; i < pgd.PageCount; i++)
{
DataRow dr1 = dt.NewRow();
dr1[0] = i;
dr1[1] = i + 1;
dt.Rows.Add(dr1);
}
DataList2.DataSource = dt;
DataList2.DataBind();
divProducts.DataSource = pgd;
divProducts.DataBind();
}
public int CurrentPageIndex
{
get
{
if (ViewState["pg"] == null)
return 0;
else
return Convert.ToInt16(ViewState["pg"]);
}
set
{
ViewState["pg"] = value;
}
}
 

Answers (1)