how pagging in datalist
how pagging in datalist like a griedview paging .send me code how to pagging in datalist in asp.net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilesh JadavPosted Jun 29, 2015, 7:32 AM
try like this :
Next, Previous, First and Last button part:
protected void lnkNext_Click(object sender, EventArgs e)
{
index += 1;
Bind();
}
protected void lnkPrev_Click(object sender, EventArgs e)
{
index -= 1;
Bind();
}
protected void lnkFirst_Click(object sender, EventArgs e)
{
index = 0;
Bind();
}
protected void lnkLast_Click(object sender, EventArgs e)
{
index = Convert.ToInt32(ViewState["LastPage"]);
Bind();
}
PagedDataSource CS Part:
public int index {
get {
if (ViewState["index"] == null)
return 0;
else
return Convert.ToInt32(ViewState["index"].ToString());
}
set{
ViewState["index"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind();
}
private void Bind()
{
DataTable dt = FillData();
if (dt.Rows.Count > 0)
{
PagedDataSource _pageDataSource = new PagedDataSource();
_pageDataSource.DataSource = dt.DefaultView;
_pageDataSource.AllowPaging = true;
_pageDataSource.PageSize = 5;
_pageDataSource.CurrentPageIndex = index;
ViewState["LastPage"] = _pageDataSource .PageCount - 1;
dlistSimilarAds.DataSource = _pageDataSource;
dlistSimilarAds.DataBind();
lnkPrev.Visible = !_pageDataSource.IsFirstPage;
lnkNext.Visible = !_pageDataSource.IsLastPage;
lnkFirst.Visible = !_ pageDataSource.IsFirstPage;
lnkLast.Visible = !_ pageDataSource.IsLastPage;
}
}
public DataTable FillData()
{
DataSet ds = new DataSet();
//Fetch data and fill your datatable
return ds.Tables[0];
}
May be this work !
Munesh SharmaPosted Jun 29, 2015, 5:19 AM
Rajeesh MenothPosted Jun 29, 2015, 5:15 AM
Upendra Pratap ShahiPosted Jun 29, 2015, 5:08 AM