In this blog we will know how to do Paging in datalist using PagedDataSource class. Drag and drop a DataList 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:DataList
ID="dl1"
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:DataList>
</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>


Join the conversation! Your thoughts help the community grow.