i have list for add_to_cart product , now i want to add pagination to it,
like first 1,2 Last, can i add pagination to this
following is my code
List<Product> prod = Session["cart"] as List<Product>;
int totalProd = prod.Count;
products_gw.DataSource = prod;
products_gw.DataBind();
and also when i remove item from then pagination get removed
following is remove item function
Button btn = (Button)sender;
int id = Convert.ToInt32(btn.CommandArgument);
int pageIndex = 1;
List<Product> prod = Session["cart"] as List<Product>;
prod.RemoveAll(r => r.prodID == id);
int totalProd = prod.Count;
products_gw.DataSource = prod;
products_gw.DataBind();
What I have tried:
i try following code
List<Product> prod = Session["cart"] as List<Product>;
int totalProd = prod.Count;
int recordCount = Convert.ToInt32(totalProd);
this.PopulatePager(recordCount, pageIndex);
<pre> private void PopulatePager(int recordCount, int currentPage)
{
try
{
double dblPageCount = (double)((decimal)recordCount / 2);
int pageCount = (int)Math.Ceiling(dblPageCount);
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
pages.Add(new ListItem("First", "1", currentPage > 1));
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new ListItem("Last", pageCount.ToString(), currentPage < pageCount));
}
rptPager.DataSource = pages;
rptPager.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}