Friday, April 23, 2010

Paging in repeater,datalist or datagrid c#

Hello Friends,
if u want to use pagging in asp.net controls, i have the simplest method for it.

just use the following code:
filename.aspx.cs file

 
protected void Page_Load(object sender, EventArgs e)
{
FetchData();
}
private void FetchData()
{
int cur_page;
if (Convert.ToInt16(Request.QueryString["page"]) > 0)
{
cur_page = Convert.ToInt16(Request.QueryString["page"]);
}
else
{ cur_page = 0; }
DataClassesDataContext db_context = new DataClassesDataContext();
        var query = (from m in db_context.tbl_name
select m).Skip(cur_page * 10).Take(10);      
lblPageName.Text = "Page: " + (cur_page+1).ToString();
prevbut.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (cur_page - 1).ToString();
nextbut.NavigateUrl=Request.CurrentExecutionFilePath+"?page="+(cur_page+1).ToString();
        Repeaterid.DataSource = query;
        Repeaterid.DataBind();
}


filename.aspx

repeater

 

                                                    Previous
                                                    Next

if u have any problem in implementing this u can mail me at
info@amitech.co
www.amitech.co

No comments:

Amitech

Hell0 Friends,
i know you are stuck with some serious problems and that's why you are here. So friends i m putting all the solved problems(with solution) that i have faced in my life (technical problems) on this blog.
In case you can not find the proper solutions, feel free to mail me at info@amitech.co
Amit Panchal