The below workss very fine , in the type for previous, next concept for paging,
i need to do with page number Like this,
1 2 3 4......23 ( http://bytes.com/topic/visual-basic-net/) Like this paging in our site........
Till 4 page visible and then last page number,,,,,? Experts plz suggest ..thx...? -
Imports System.Data
-
Imports System.Data.SqlClient
-
-
Partial Public Class pagingtest
-
Inherits System.Web.UI.Page
-
Private pagedData As New PagedDataSource()
-
Private CurPage As Integer = 1
-
-
Private Sub Page_Load(ByVal obj As [Object], ByVal e As EventArgs) Handles Me.Load
-
doPaging()
-
End Sub
-
-
Public Function getTheData() As DataTable
-
-
Dim DS As New DataSet()
-
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
-
-
Dim objSQLAdapter As New SqlDataAdapter("SELECT CompanyName, ContactName, ContactTitle FROM Customers", myConnection)
-
objSQLAdapter.Fill(DS, "Customers")
-
Return (DS.Tables(0))
-
-
-
End Function
-
-
Private Sub doPaging()
-
-
pagedData.DataSource = getTheData().DefaultView
-
-
pagedData.AllowPaging = True
-
pagedData.PageSize = 4
-
Try
-
If Request("Page").ToString() IsNot Nothing Then
-
CurPage = Int32.Parse(Request("Page").ToString())
-
Else
-
CurPage = 1
-
End If
-
-
pagedData.CurrentPageIndex = CurPage - 1
-
Catch ex As Exception
-
-
pagedData.CurrentPageIndex = 0
-
End Try
-
-
btnPrev.Enabled = (Not pagedData.IsFirstPage)
-
'btnPrev.Visible = (!pagedData.IsFirstPage);
-
-
btnFirst.Enabled = (Not pagedData.IsFirstPage)
-
-
btnNext.Enabled = (Not pagedData.IsLastPage)
-
'btnNext.Visible = (!pagedData.IsLastPage);
-
-
btnLast.Enabled = (Not pagedData.IsLastPage)
-
-
'pagedData.CurrentPageIndex = CurPage - 1;
-
-
lblCurrentPage.Text = ("Page: " & CurPage.ToString() & " of ") & pagedData.PageCount.ToString()
-
-
theDataList.DataSource = pagedData
-
-
theDataList.DataBind()
-
End Sub
-
-
Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As EventArgs)
-
Response.Redirect((Request.CurrentExecutionFilePath & "?Page=") & (CurPage - 1))
-
End Sub
-
-
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs)
-
Response.Redirect((Request.CurrentExecutionFilePath & "?Page=") & (CurPage + 1))
-
End Sub
-
-
Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As EventArgs)
-
Response.Redirect((Request.CurrentExecutionFilePath & "?Page=") & (1))
-
End Sub
-
-
Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As EventArgs)
-
Response.Redirect((Request.CurrentExecutionFilePath & "?Page=") & (pagedData.PageCount))
-
End Sub
-
End Class
-
-
<div>
-
<asp:DataList id="theDataList" runat="server">
-
-
<ItemTemplate>
-
-
<table border="0" cellpadding="0" cellspacing="0" width="500">
-
-
<tr>
-
-
<td width="140"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Company Name</strong>:</font></td>
-
-
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><%# DataBinder.Eval(Container.DataItem, "CompanyName") %></font></td>
-
-
</tr>
-
-
<tr>
-
-
<td width="110"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Contact Name</strong>:</font></td>
-
-
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><%# DataBinder.Eval(Container.DataItem, "ContactName") %></td>
-
-
</tr>
-
-
<tr>
-
-
<td width="110"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Contact Title</strong>:</font></td>
-
-
<td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></font></td>
-
-
</tr>
-
-
</table>
-
-
</ItemTemplate>
-
-
<separatortemplate>
-
-
<hr color="#0099FF" />
-
-
</separatortemplate>
-
-
</asp:DataList>
-
<asp:LinkButton ID="btnFirst" runat="server" OnClick="btnFirst_Click">First</asp:LinkButton>
-
<asp:LinkButton id="btnPrev" Text="Prev" OnClick="btnPrev_Click" runat="server" />
-
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
-
<asp:LinkButton id="btnNext" Text="Next" OnClick="btnNext_Click" runat="server" />
-
<asp:LinkButton ID="btnLast" runat="server" OnClick="btnLast_Click"/>
-
</div>
-
-
2 2782
I'm not exactly sure what your problem is....
But you don't have to do Redirects for paging purposes.
You could simply store the page number that the user is viewing in Session, ViewState, Cookies, or even a HiddenField so that you can set the page index based on the last index that the user was viewing.
In the following example (based on your project), I'm storing the page index that the user is viewing in ViewState.
Here is the ASP code for the page: -
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="pagingtest.aspx.vb" Inherits="MyNamespace.pagingtest" %>
-
-
<!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></title>
-
<style type="text/css">
-
.prompt
-
{
-
font-weight: bold;
-
display: block;
-
width: 150px;
-
float: left;
-
}
-
.value
-
{
-
font-style: italic;
-
float: left;
-
}
-
.promptValueGroup
-
{
-
clear: both;
-
}
-
.listItemStyle
-
{
-
font-family: Verdana, Arial, Helvetica, sans-serif;
-
border-bottom: solid 1px #0099FF;
-
margin-bottom:4px;
-
}
-
</style>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
-
<asp:DataList ID="theDataList" runat="server">
-
<ItemTemplate>
-
<div class="listItemStyle">
-
<div class="promptValueGroup">
-
<span class="prompt">Company Name:</span>
-
<span class="value"><%# DataBinder.Eval(Container.DataItem, "CompanyName") %></span>
-
</div>
-
<div class="promptValueGroup">
-
<span class="prompt">Contact Name: </span>
-
<span class="value"><%# DataBinder.Eval(Container.DataItem, "ContactName") %></span>
-
</div>
-
<div class="promptValueGroup">
-
<span class="prompt">Contact Title: </span>
-
<span class="value"><%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></span>
-
</div>
-
<div style="clear:both"></div>
-
</div>
-
</ItemTemplate>
-
</asp:DataList>
-
<asp:LinkButton ID="btnFirst" runat="server" OnClick="btnFirst_Click" Text="first"></asp:LinkButton>
-
<asp:LinkButton ID="btnPrev" Text="<<" OnClick="btnPrev_Click" runat="server" />
-
<asp:Label ID="lblCurrentPage" runat="server"></asp:Label>
-
<asp:LinkButton ID="btnNext" Text=">>" OnClick="btnNext_Click" runat="server" />
-
<asp:LinkButton ID="btnLast" runat="server" OnClick="btnLast_Click" Text="last"></asp:LinkButton>
-
-
</form>
-
</body>
-
</html>
-
Here is the VB code that handles the paging for the list (please take note of the comments for more details about what I'm doing) -
Imports System.Data
-
Imports System.Data.SqlClient
-
-
Partial Public Class pagingtest
-
Inherits System.Web.UI.Page
-
-
Private pagedData As New PagedDataSource
-
Private currentPage As Integer
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
'This method handles the Page Load event.
-
'It is executed before an events (like button clicks)
-
-
'Initializing the paged data source and retrieving the
-
'page index of the page that the user is viewing
-
initializePagedData()
-
-
End Sub
-
-
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
-
-
-
'This method handles the aPage's PreRender event .
-
'It is executed after your page's event's are finished executing
-
'(after the button click code is executed) and just before
-
'everything is converted into HTML.
-
'It's pretty much the last step that's done before the page is sent back
-
'to the user.
-
-
'At this point, all changes the the paged data source will have been made
-
'so I'm calling the method that is responsible for binding the paged data
-
'source to the list and saving the paging information for next time.
-
-
'Displaying the paged data in the data list
-
displayPagedDataInList()
-
End Sub
-
-
Private Function getTheData() As DataView
-
-
'You should replace this code with the code that retrieves
-
'The data from your DataBase.
-
'Please note that this function has been modified to return a DataView
-
'The DataView returned by this method is based on the Table retrieved
-
'from the data base....
-
-
'Your method would look something like:
-
-
' Dim DS As New DataSet()
-
' Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
-
-
' Dim objSQLAdapter As New SqlDataAdapter("SELECT CompanyName, ContactName, ContactTitle FROM Customers", myConnection)
-
' objSQLAdapter.Fill(DS, "Customers")
-
' Return DS.Tables(0).DefaultView
-
-
Dim dt As New DataTable
-
dt.Columns.Add(New DataColumn("CompanyName"))
-
dt.Columns.Add(New DataColumn("ContactName"))
-
dt.Columns.Add(New DataColumn("ContactTitle"))
-
-
Dim dr As DataRow
-
-
For i As Integer = 1 To 20
-
dr = dt.NewRow
-
dr("CompanyName") = "Company " + i.ToString
-
dr("ContactName") = "Contact for company " + i.ToString
-
dr("ContactTitle") = "Contact title for company " + i.ToString
-
dt.Rows.Add(dr)
-
Next
-
-
Return New DataView(dt)
-
-
End Function
-
-
Private Sub initializePagedData()
-
'Retrieving the data source for the paged data source
-
Dim ds As DataView = getTheData()
-
-
'Setting the data source for the paged data source
-
pagedData.DataSource = ds
-
-
'Configuring the paged data source to allow paging
-
pagedData.AllowPaging = True
-
-
'Configuring the paged data source to display 5 items at a time
-
pagedData.PageSize = 5
-
-
'Retrieving the page index the user was last viewing
-
currentPage = CType(ViewState("currPage"), Integer)
-
End Sub
-
-
Private Sub displayPagedDataInList()
-
'Displaying details about which page the user is currently veiwing
-
lblCurrentPage.Text = (currentPage + 1).ToString + "/" + pagedData.PageCount.ToString
-
-
'Saving the page number
-
ViewState("currPage") = currentPage
-
-
'Setting current index of the paged data
-
pagedData.CurrentPageIndex = currentPage
-
-
'Binding the list to the paged data
-
theDataList.DataSource = pagedData
-
theDataList.DataBind()
-
-
'Configuring paging buttons according the page the user's currently viewing
-
btnPrev.Enabled = (Not pagedData.IsFirstPage)
-
btnFirst.Enabled = (Not pagedData.IsFirstPage)
-
btnNext.Enabled = (Not pagedData.IsLastPage)
-
btnLast.Enabled = (Not pagedData.IsLastPage)
-
End Sub
-
-
Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As EventArgs)
-
-
'Moving to the previous page as long as it's not the first page
-
If currentPage > 0 Then
-
currentPage -= 1
-
End If
-
-
End Sub
-
-
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs)
-
-
'Moving to the next page as long as it's not the last page
-
If currentPage < pagedData.PageCount - 1 Then
-
currentPage += 1
-
End If
-
-
End Sub
-
-
Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As EventArgs)
-
'Moving the current page to the first page
-
currentPage = 0
-
End Sub
-
-
Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As EventArgs)
-
'Moving the current page to the last page
-
currentPage = pagedData.PageCount - 1
-
End Sub
-
-
End Class
-
This one worked greatly.....!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: enak |
last post by:
I can not get my datagrid to page. I have a datagrid that
I can sort 2 of the columns. This works great. I added
paging and when I display the dg it shows 5 pages. (I am
showing page numbers at...
|
by: David |
last post by:
Hello.
How can I enable and manage paging capability on DataList control like
DataGrid?
Thank you.
|
by: SouthSpawn |
last post by:
Hello,
I have an asp.net application that will use a SQL Server DBMS for the
backend.
On my asp.net form. I have a next, previous, last and first buttons on my
form.
Basically, this...
|
by: Maria |
last post by:
Hi,
I have read about paging, segmentation and paged segmentation and I
believe I have (nearly) understood how these techniques are implemented
in hardware. However, I am till confused about the...
|
by: farhad13841384 |
last post by:
Hi , I Hope You fine.
I have some problem with this code for paging in asp.net
this bottom code work correctly without any error but when
I try to place separate code in .VB file then error is...
|
by: needin4mation |
last post by:
Hi, I have read many different datalist paging solutions, including
using the ROW_NUMBER() with Sql Server 2005. I have googled various
methods to use with lower versions of Sql Server.
I...
|
by: Aussie Rules |
last post by:
Hi,
Is it possible to have some sort of paging (prev/next page) feature with the
data list.
I have a datalist, that can display several hundred items, and I want to
have say 20 to a page.
...
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= |
last post by:
Hi misters,
I have an application web asp.net 2.0. I have a aspx page with Datalist and
paging.
Now, I want that the user can select several rows of DataList (multiple
selection) and maintain...
|
by: wallconor |
last post by:
Hi,
I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |