In Focus
Jabalpur Chapter Meet July 13: Register Now
Chandigarh Chapter: Developers Day on 29 June 2013
Delhi Chapter Hands On June 22: Limited Seats Register Now
Email :
Password :
Remember me?
Forgot password
Contribute
An Article
A Blog
A News
A Video
A Link
An Interview Question
Ask a Question
TECHNOLOGIES
.NET 4.5
Chapters
JavaScript, CSS
SharePoint 2010
Web Development
.NET Assemblies
Coding Best Practices
JQuery
SharePoint 2013
Web Services in C#
ADO.NET in C#
Current Affairs
JSP
Silverlight with C#
Windows 8
AJAX in C#
Databases & DBA
Leadership
Smart Devices
Windows Azure
Android Programming
Design & Architecture
Learn .NET
SQL
Windows Controls C#
Articles C#
Exception Handling C#
LightSwitch 2012
SQL Server 2012
Windows Forms C#
ASP.NET Controls in C#
Expression Studio
LINQ
Testing
Windows Phone 8
ASP.NET MVC with C#
Graphics Design
Mobile & Embedded
TypeScript
Windows Server 2012
ASP.NET Programming
How do I
Office 2013
Visual C#
Windows Store Apps
BizTalk Server
HTML 5
OOP/OOD
Visual Studio .NET
Workflow Foundation in C#
C# Language
Internet & Web
Operating Systems
Visual Studio 2010
WPF
C# Tutorials
iPhone/iPad
PHP
Visual Studio 2012
XAML
C, C++, MFC
Java
Products
WCF with C#
XML
Career Advice
Java and .NET
Project Management
Request a new Category
|
View All
ANSWERS
BLOGS
VIDEOS
INTERVIEWS
BOOKS
LINKS
NEWS
CHAPTERS
CAREER ADVICE
iOS 7 beta: Testers warned when using uncert ...
Advantages of C# Over Java
Design Simple Logo with help of Expression D ...
IN Query in LINQ
Menu Style like jQuery
Implementation of Abstract Factory Pattern w ...
Why Constructor can't be declared Virtually? ...
Send Email in HTML Format using SQL database ...
Waiting Message in Window Application using C#
Merging Several Rows into a Single Row in SQ ...
Blog
5
10,538
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
2840
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
This Feature is Sponsored By
DynamicPDF Merger is a developers dream for interacting with any existing PDF documents. Merge, append, split, form fill, flatten stamp and so much more.
Random display of records in gri..
Binding in an ASP.NET DropDownList
comments
View Previous Comments
of
COMMENT USING
PREMIUM SPONSORS
DynamicPDF Developer Components
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
More Blogs from this Blogger
Validate TextBox using JavaScript
Display XML File Data into GridView using DataTable
Search Record Display in GridView
Display Data from Database to Label
Delete multiple row by selecting checkbox on Data Gridview
Update Male TO Female and Female To Male with single query
Display username belong to selected item value from combo box
Related records from one textbox to another
Fetch multiple items to combobox from db
Uncheck CheckBoxList items when button is clicked
View All
SPONSORED BY
Get the industry leading .NET Diagramming component
.NET Diagramming framework designed for creating advanced solutions
Follow @twitterapi
Latest Blogs
In Defence of Books
Media Player, Real Player, QuickTime Player in ASP.Net
Credit Card Payment in ASP.Net using Stripe.com
Crop Image in ASP.Net using Script
Creating Social Site Buttons By addthis.com in ASP.Net
Internals of C# Events
Design Simple Logo with help of Expression Design
How to get list of all folders in a Dropdown List
Search in Coma delimited string
Get the Values of CheckBoxList in Comma Separated form using jQuery
View All
Poll
Result
All Polls
Speed of C# Corner
How do you find speed of C# Corner when visiting the site?
Very Fast
OK
Slow
Very Slow
How do you find speed of C# Corner when visiting the site?
Options
Votes
%
Very Fast
4
7.69
OK
42
80.77
Slow
4
7.69
Very Slow
2
3.85
Total
52
100%