C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to do Paging with Repeater control


Posted Date: 15 May 2008    Resource Type: Code Snippets    Category: Databinding
Author: Ramasamy.NMember Level: Gold    
Rating: Points: 10



The following code shows how to do Paging with Repeater control


protected void Page_Load(object sender, EventArgs e)
{




if (!IsPostBack)
{
Application["index"] = 0;
display();

}









}
protected void previous_Click(object sender, EventArgs e)
{


if ( System.Convert.ToInt32(Application["index"]) > 1)
{


Application["index"] = System.Convert.ToInt32(Application["index"]) - 1;



}

display();

}
protected void next_Click(object sender, EventArgs e)
{
if (System.Convert.ToInt32(Application["index"]) < System.Convert.ToInt32(Application["count"]))
{

Application["index"] = System.Convert.ToInt32(Application["index"]) + 1;


}
display();

}
public void display()
{


OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/registration.mdb"));
conn.Open();
OleDbDataAdapter adpter = new OleDbDataAdapter("select * from students", conn);
DataSet data = new DataSet();
adpter.Fill(data);
PagedDataSource paging = new PagedDataSource();
paging.DataSource = data.Tables[0].DefaultView;
paging.AllowPaging = true;
paging.PageSize = 2;
Application["count"] = paging.PageCount;

paging.CurrentPageIndex = System.Convert.ToInt32(Application["index"]);
Application["current"] = paging.CurrentPageIndex;
result.DataSource = paging;
result.DataBind();

}
protected void result_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
if (System.Convert.ToInt32(Application["current"]) == 0)
{


((LinkButton)e.Item.FindControl("previous")).Enabled = false;


}
else
{

((LinkButton)e.Item.FindControl("previous")).Enabled = true;

}
}


if (e.Item.ItemType == ListItemType.Header)
{
if (System.Convert.ToInt32(Application["current"]) == System.Convert.ToInt32(Application["count"]) - 1)
{

((LinkButton)e.Item.FindControl("next")).Enabled = false;


}
else
{

((LinkButton)e.Item.FindControl("next")).Enabled = true;

}
}


}


Attachments

  • Paging with Repeater control (16319-15157-coding.zip)



  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Repeater control  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: How to retrieve populated datatable from sql server
    Previous Resource: Dynamically Bind C# ASP.NET GridView
    Return to Discussion Resource Index
    Post New Resource
    Category: Databinding


    Post resources and earn money!
     
    Related Resources



    dotNet Slackers   BizTalk Adaptors    Web Design


    Contact Us    Privacy Policy    Terms Of Use