23 April 2010

Paging in repeater,datalist or datagrid c#

Written by Amit Panchal, Posted in Blog

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 you have any doubts feel free to comment us

Social Bookmarks

About the Author

Amit Panchal

Co-Founder,

Amitech Business Solutions

All Events

Textify

Comments (0)

Leave a comment

You are commenting as guest. Optional login below.

Cancel Submitting comment...