Tweet
SIGN UP
MEMBER LOGIN:
TECHNOLOGIES
.NET 4.5
.NET Remoting in C#
Active Directory C#
ADO.NET in C#
AJAX in C#
Algorithms in C#
Android Programming
Articles C#
ASP, JavaScript, CSS
ASP.NET Controls in C#
ASP.NET MVC with C#
ASP.NET Programming
BizTalk Server
C# Assemblies
C# Language
C# Tutorials
C, C++, MFC
Career Advice
Chapters
Cloud Computing
COBOL.NET
Coding Best Practices
COM Interop
Compact Framework
Cryptography C#
Crystal Reports C#
Current Affairs
Custom Controls C#
Databases & DBA
Deployment
Design & Architecture
DirectX C#
Enterprise Development
Error Zone
Exception Handling C#
Expression Studio
F#
Files, Directories in C#
Financial Applications
Games Programming C#
GDI+ & Graphics
Hardware
How do I
HTML 5
Internet & Web
iPhone/iPad
Java
Java and .NET
JQuery
JSP
Leadership
Learn .NET
LINQ with C#
Metro Style Apps in C#
Mobile & Embedded
MonoDevelop
MSMQ in C#
Multithreading in C#
Networking
Office Development
OOP/OOD
Operating Systems
PHP
Printing in C#
Products
Project Management
Reports using C#
Robotics & Hardware
Security in .NET
SharePoint
Silverlight with C#
Smart Devices
Speech in C#
SQL
SQL Server 2012
String in C#
Team Foundation & VSS
Testing
Visual Basic .NET
Visual C#
Visual Studio .NET
Visual Studio 11
Visual Studio 2010
VS LightSwitch 2011
WCF with C#
Web Forms C#
Web Services in C#
WebForms Controls
Windows 8 in C#
Windows Controls C#
Windows Forms C#
Windows Phone in C#
Windows PowerShell
Windows Services in C#
Workflow Foundation in C#
WPF with C#
XAML with C#
XML in C#
XNA with C#
FORUMS
BLOGS
VIDEOS
INTERVIEWS
CERTIFICATIONS
DOWNLOADS
BOOKS
LINKS
NEWS
Learn .NET in 60 days – Part 1 (13 Labs)
Learn MVC (Model view controller) Step by Step ...
Learn C# Corner - Home
Using Border Radius and Gradients in CSS3: Part I
Learn C# Corner - Footer
Learn .NET and C# in 60 Days Lab13(Day 5): - C ...
iPhone 5 First Look
Samsung Galaxy Note Review
WCF - Authentication and Authorization in Ente ...
How to write a good article on C# Corner
Blog
Paging in repeater using PagedDataSource class
Posted by
Satyapriya Nayak
in
Blogs
|
ASP.NET Controls in C#
on
Sep 12, 2011
In this article we will know how to do Paging in repeater using PagedDataSource class.
Tweet
1290
0
0
Download Files:
Paging.rar
Drag and drop a Repeater control, one label, and two buttons controls to the WebPages.
Table structure
Program
Default.aspx code
<%
@
Page
Language
="C#"
AutoEventWireup
="true"
CodeFile
="Default.aspx.cs"
Inherits
="_Default"
%>
<!
DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
="http://www.w3.org/1999/xhtml">
<
head
runat
="server">
<
title
>
Untitled Page
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server">
<
div
>
<
table
border
="1">
<
asp
:
repeater
id
="repeater1"
runat
="server">
<
HeaderTemplate
>
<
font
color
="red"><
b
>
Employee Details
</
b
></
font
>
</
HeaderTemplate
>
<
itemtemplate
>
<
tr
>
<
td
><
font
color
="Green"><
b
>
ID
</
b
></
font
></
td
>
<
td
><
font
color
="Green"><
b
>
NAME
</
b
></
font
></
td
>
<
td
><
font
color
="Green"><
b
>
SALARY
</
b
></
font
></
td
>
<
td
><
font
color
="Green"><
b
>
ADDRESS
</
b
></
font
></
td
>
<
td
><
font
color
="Green"><
b
>
DESIGNATION
</
b
></
font
></
td
>
</
tr
>
<
tr
>
<
td
>
<
font
color
="#ff8000"><
b
>
<%
#
Eval(
"empid"
)
%>
</
b
></
font
></
td
>
<
td
>
<
font
color
="Fuchsia"><
b
>
<%
#
Eval(
"empname"
)
%>
</
b
></
font
></
td
>
<
td
>
<
font
color
="#663300"><
b
>
<%
#
Eval(
"empsal"
)
%>
</
b
></
font
></
td
>
<
td
>
<
font
color
="Purple"><
b
>
<%
#
Eval(
"empadd"
)
%>
</
b
></
font
></
td
>
<
td
>
<
font
color
="#808040"><
b
>
<%
#
Eval(
"empdes"
)
%>
</
b
></
font
></
td
>
</
tr
>
</
itemtemplate
>
</
asp
:
repeater
>
</
table
>
<
table
width
="100%"
border
="0">
<
tr
>
<
td
>
<
asp
:
label
id
="lbl1"
runat
="server"
BackColor
="Yellow"
BorderColor
="Yellow"
Font-Bold
="True"
ForeColor
="#FF3300"></
asp
:
label
></
td
>
</
tr
>
<
tr
>
<
td
>
<
asp
:
button
id
="btnPrevious"
runat
="server"
text
="Previous"
Width
="60px"
onclick
="btnPrevious_Click"></
asp
:
button
>
<
asp
:
button
id
="btnNext"
runat
="server"
text
="Next"
Width
="60px"
onclick
="btnNext_Click"></
asp
:
button
></
td
>
</
tr
>
</
table
>
</
div
>
</
form
>
</
body
>
</
html
>
Default.aspx.cs code
using
System;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
System.Data.SqlClient;
public
partial
class
_Default
: System.Web.UI.
Page
{
string
strConnString =
ConfigurationManager
.ConnectionStrings[
"ConnectionString"
].ConnectionString;
string
str;
SqlCommand
com;
SqlDataAdapter
sqlda;
DataSet
ds;
protected
void
Page_Load(
object
sender,
EventArgs
e)
{
if
(!IsPostBack)
{
bindrepeater();
}
}
private
void
bindrepeater()
{
SqlConnection
con =
new
SqlConnection
(strConnString);
con.Open();
str =
"select * from employee"
;
com =
new
SqlCommand
(str, con);
sqlda =
new
SqlDataAdapter
(com);
ds =
new
DataSet
();
sqlda.Fill(ds,
"employee"
);
PagedDataSource
Pds1 =
new
PagedDataSource
();
Pds1.DataSource = ds.Tables[0].DefaultView;
Pds1.AllowPaging =
true
;
Pds1.PageSize = 3;
Pds1.CurrentPageIndex = CurrentPage;
lbl1.Text =
"Showing Page: "
+ (CurrentPage + 1).ToString() +
" of "
+ Pds1.PageCount.ToString();
btnPrevious.Enabled = !Pds1.IsFirstPage;
btnNext.Enabled = !Pds1.IsLastPage;
repeater1.DataSource = Pds1;
repeater1.DataBind();
con.Close();
}
public
int
CurrentPage
{
get
{
object
s1 =
this
.ViewState[
"CurrentPage"
];
if
(s1 ==
null
)
{
return
0;
}
else
{
return
Convert
.ToInt32(s1);
}
}
set
{
this
.ViewState[
"CurrentPage"
] =
value
; }
}
protected
void
btnPrevious_Click(
object
sender,
EventArgs
e)
{
CurrentPage -= 1;
bindrepeater();
}
protected
void
btnNext_Click(
object
sender,
EventArgs
e)
{
CurrentPage += 1;
bindrepeater();
}
}
Output
Thanks for reading
share this blog :
Random display of records in gri..
Binding in an ASP.NET DropDownList
Related Blogs
Custom Paging of GridView or DataListview or Repeater Control
Listview or Datalist paging
Multiview with view control in web application
Automatioc refresh Asp.Net Page
Automatically referesh a ASP.NET page
Gudiya's Web Page
post comment
Sponsored by
Become a Sponsor
More Blogs from this Blogger
Display records in a list view (web) from the database.
Display records in a listview (windows) from the database
Edit multiple records in a Grid view
TreeView in ASP.NET
Show success after inserting a value without using label (using java script)
Calendar control DayRender event
Insert data from Gridview to database
Change old password to new password in Asp.net
Export gridview records to word file
Insert Value from Checkbox in MySql Database in PHP
View All
Latest Blogs
Free Ride is Over for Desktop Developers in Visual Studio 11
DotNet developers most used application/tools launching through 'Run'
80-inch Windows 8 Tablet
Data encapsulation
Option to access the Column Names in Data table
Open multiple windows in browser startup. (Multiple homepages option)
I'm Sorry
const and readonly
Address, Binding and Contract in WCF
JQuery Maxchars Plugin
View All
Sponsored by
Become a Sponsor