In this blog we will know about how to do a custom paging containing a dropdown list pager with the help of a Datagrid control.
Features to do
1.Here we will have four link buttons to navigate the records as first, previous, next and last. Tooltip is added to each link buttons.
2.We have a label control where we can know how many records are present in the database.
3.We have a Dropdown List where its list item is bound with some numbers. So when we choose any number from the dropdown list that number of records will be display in the datagrid.
4.While navigating the records we have a page count, which is displayed in the label control. Here we can know what page of results we are currently viewing.
In .net framework 3.5 no datagrid is available in the toolbox. So we have to make it available in the toolbox. To do that right click on the toolbox then click choose items, then check all the checkbox present near datagrid and click ok. You will notice that datagrid control is added to the toolbox.
Table structure
Create table employee(empid int primary key,empname varchar(50),empsal int,empadd varchar(50),empdes varchar(50))
Default.aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Datagrid paging with dropdown</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<asp:Datagrid id="dg1" runat="server" AutoGenerateColumns="true"
AllowPaging="True" AllowCustomPaging="False"
PagerStyle-Visible = "False" HeaderStyle-BackColor="Red"
HeaderStyle-ForeColor="White" BackColor="#FFCC66" >
<PagerStyle Visible="False"></PagerStyle>
<AlternatingItemStyle BackColor="#FFFFCC" />
<HeaderStyle BackColor="Red" ForeColor="White"></HeaderStyle>
</asp:Datagrid>
<asp:linkbutton id="Firstbutton"
Text="<< 1st
Page" CommandArgument="0"
runat="server" onClick="NavigateButtonClick" ForeColor="#333300"
ToolTip="First"/>
<asp:linkbutton id="Prevbutton"
Text= "" CommandArgument="prev" runat="server"
onClick="NavigateButtonClick" ForeColor="#333300"
ToolTip="Previous"/>
<asp:linkbutton id="Nextbutton"
Text= "" CommandArgument="next" runat="server"
onClick="NavigateButtonClick" ForeColor="#333300"
ToolTip="Next"/>
<asp:linkbutton
id="Lastbutton"
Text="Last Page
>>" CommandArgument="last"
runat="server" onClick="NavigateButtonClick" ForeColor="#333300"
ToolTip="Last"/>
<br
/><br />
<asp:Label id="PageCount"
runat="server"
/><br />
<asp:label id="TotalRecords"
runat="server"
/> <br /> <br
/><br/><br />
Change Pagesize <asp:DropDownList id="d1" runat="server" ForeColor="Maroon">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem Selected="True">4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>

Join the conversation! Your thoughts help the community grow.