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 begin and occured .I want to separate this code and compiling .vb code using VBC.exe later .(bin/paging.dll)
when do it like me so you retrive only < Previous Page Next Page > in your web browser and you don't retrive list Of data in your web browser.
then i try this job and place <% dopagin() %> in paging.aspx file between <body> ... </body>
then i retrive list of data but when you click next you cannot navigate than more 1 page and when
you click previous page you get error "Index -5 is not non-negative and below total rows count"
how can i correct this code .somebody help me please
thank you very much -
-
-------------Correct pagingDS.aspx Code begin ---------------------
-
-
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
-
<%@ Import Namespace="System.Data" %>
-
<%@ Import Namespace="System.Data.SQLClient" %>
-
-
<script language="VB" runat="server">
-
Dim pagedData As New pagedDataSource
-
-
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
-
doPaging()
-
End Sub
-
-
Function getTheData() As DataTable
-
Dim DS As New DataSet()
-
Dim strConnect As New SQLConnection("server=localhost;uid=sa;pwd=relayer;Database=Northwind")
-
Dim objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
-
objSQLAdapter.Fill(DS, "customers")
-
-
Return DS.Tables("customers").Copy
-
End Function
-
-
Sub doPaging()
-
pagedData.DataSource = getTheData().DefaultView
-
pagedData.AllowPaging = True
-
pagedData.PageSize = 5
-
-
Try
-
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
-
Catch ex As Exception
-
pagedData.CurrentPageIndex = 0
-
End Try
-
-
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
-
btnNext.Visible = ( NOT pagedData.IsLastPage )
-
-
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
-
-
theDataList.DataSource = pagedData
-
theDataList.DataBind()
-
End Sub
-
-
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
-
End Sub
-
-
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
-
End Sub
-
</script>
-
<html>
-
<head>
-
<title>Paging with ASP.NET - DataSet Example - VB.NET</title>
-
</head>
-
<body>
-
<form runat="server">
-
<font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
-
<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="btnPrev" Text="<" OnClick="Prev_Click" runat="server" />
-
<asp:LinkButton id="btnNext" Text=">" OnClick="Next_Click" runat="server" />
-
</form>
-
</body>
-
</html>
-
-
-------------------Paging.aspx End Code-----------------------------------------
-
-
-
***********************************************************************
-
-
-
---------------MY .ASPX file begin------------------------
-
-
<%@ Page src="paging.vb" language="vb" AutoEventWireup="false" Explicit="True" Inherits="farhad.myfunction2" ContentType="text/html" %>
-
-
<html>
-
<head>
-
<title>Paging with ASP.NET - DataSet Example - VB.NET</title>
-
</head>
-
<body>
-
<form runat="server">
-
<font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
-
<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="btnPrev" Text="< Previous Page" OnClick="Prev_Click" runat="server" />
-
<asp:LinkButton id="btnNext" Text="Next Page > " OnClick="Next_Click" runat="server" />
-
</form>
-
</body>
-
</html>
-
-
------------End My ASPX file ------------------------------
-
-
*************************************************
-
-------MY .VB Code AND CLASS begin--> Paging.vb --------------------
-
Imports System
-
Imports System.Data
-
Imports System.Data.SQLClient
-
Imports System.Web
-
Imports System.Web.UI
-
Imports System.Web.UI.Webcontrols
-
Imports System.Xml
-
-
-
namespace farhad
-
-
public class myfunction2 : Inherits Page
-
-
public pagedData As New pagedDataSource
-
public ds As New DataSet()
-
public strConnect As New SQLConnection("server=localhost;uid=sa;pwd=mysecretpass;Database=northwind")
-
public objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
-
public btnPrev AS LinkButton
-
public btnNext AS LinkButton
-
public pageNumber AS Label
-
public theDataList AS DataList
-
-
public Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
-
dopaging()
-
end sub
-
public function getTheData() As DataTable
-
-
objSQLAdapter.Fill(DS, "customers")
-
-
Return DS.Tables("customers").Copy
-
End function
-
-
public Sub doPaging()
-
pagedData.DataSource = getTheData().DefaultView
-
pagedData.AllowPaging = True
-
pagedData.PageSize = 5
-
-
Try
-
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
-
Catch ex As Exception
-
pagedData.CurrentPageIndex = 0
-
End Try
-
-
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
-
btnNext.Visible = ( NOT pagedData.IsLastPage )
-
-
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
-
-
theDataList.DataSource = pagedData
-
theDataList.DataBind()
-
End Sub
-
-
public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
-
End Sub
-
-
public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
-
End Sub
-
-
end class
-
end namespace
-
----------------------End My CLASS IN paging.VB FILE----------
-
2 6372
play with the index
If pagedData.CurrentPageIndex < 0 Then
pagedData.CurrentPageIndex = pagedData.CurrentPageIndex + (-pagedData.CurrentPageIndex)
End If
theDataList.DataSource = pagedData
theDataList.DataBind()
i have added this part to the dopaging() and things worked.
sorry for previous post. i have corrected your code better. i hope it helps. im sending you dopaging sub only. but there are some extra controls that i have used. filter them please.
Sub doPaging()
pagedData.DataSource = getTheData().DefaultView
pagedData.AllowPaging = True
pagedData.PageSize = 5
Dim deg As Integer
Try
deg = Int32.Parse(Request.QueryString("Page"))
Catch ex As Exception
deg = 0
End Try
If deg < 0 Then
deg = deg + (-deg)
End If
Try
pagedData.CurrentPageIndex = deg
Catch ex As Exception
pagedData.CurrentPageIndex = 0
End Try
btnPrev.Visible = (Not pagedData.IsFirstPage)
btnNext.Visible = (Not pagedData.IsLastPage)
pageNumber.Text = pagedData.PageCount & " de " & (pagedData.CurrentPageIndex + 1)
pageNumber1.Text = pagedData.PageCount & " de " & (pagedData.CurrentPageIndex + 1)
If pagedData.CurrentPageIndex < 0 Then
pagedData.CurrentPageIndex = pagedData.CurrentPageIndex + (-pagedData.CurrentPageIndex)
End If
theDataList.DataSource = pagedData
theDataList.DataBind()
End Sub
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 begin and occured .I want to separate this code and compiling .vb code using VBC.exe later .(bin/paging.dll)
when do it like me so you retrive only < Previous Page Next Page > in your web browser and you don't retrive list Of data in your web browser.
then i try this job and place <% dopagin() %> in paging.aspx file between <body> ... </body>
then i retrive list of data but when you click next you cannot navigate than more 1 page and when
you click previous page you get error "Index -5 is not non-negative and below total rows count"
how can i correct this code .somebody help me please
thank you very much -
-
-------------Correct pagingDS.aspx Code begin ---------------------
-
-
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
-
<%@ Import Namespace="System.Data" %>
-
<%@ Import Namespace="System.Data.SQLClient" %>
-
-
<script language="VB" runat="server">
-
Dim pagedData As New pagedDataSource
-
-
Sub Page_Load(byVal obj As Object, byVal e As EventArgs)
-
doPaging()
-
End Sub
-
-
Function getTheData() As DataTable
-
Dim DS As New DataSet()
-
Dim strConnect As New SQLConnection("server=localhost;uid=sa;pwd=relayer;Database=Northwind")
-
Dim objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
-
objSQLAdapter.Fill(DS, "customers")
-
-
Return DS.Tables("customers").Copy
-
End Function
-
-
Sub doPaging()
-
pagedData.DataSource = getTheData().DefaultView
-
pagedData.AllowPaging = True
-
pagedData.PageSize = 5
-
-
Try
-
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
-
Catch ex As Exception
-
pagedData.CurrentPageIndex = 0
-
End Try
-
-
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
-
btnNext.Visible = ( NOT pagedData.IsLastPage )
-
-
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
-
-
theDataList.DataSource = pagedData
-
theDataList.DataBind()
-
End Sub
-
-
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
-
End Sub
-
-
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
-
End Sub
-
</script>
-
<html>
-
<head>
-
<title>Paging with ASP.NET - DataSet Example - VB.NET</title>
-
</head>
-
<body>
-
<form runat="server">
-
<font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
-
<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="btnPrev" Text="<" OnClick="Prev_Click" runat="server" />
-
<asp:LinkButton id="btnNext" Text=">" OnClick="Next_Click" runat="server" />
-
</form>
-
</body>
-
</html>
-
-
-------------------Paging.aspx End Code-----------------------------------------
-
-
-
***********************************************************************
-
-
-
---------------MY .ASPX file begin------------------------
-
-
<%@ Page src="paging.vb" language="vb" AutoEventWireup="false" Explicit="True" Inherits="farhad.myfunction2" ContentType="text/html" %>
-
-
<html>
-
<head>
-
<title>Paging with ASP.NET - DataSet Example - VB.NET</title>
-
</head>
-
<body>
-
<form runat="server">
-
<font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
-
<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="btnPrev" Text="< Previous Page" OnClick="Prev_Click" runat="server" />
-
<asp:LinkButton id="btnNext" Text="Next Page > " OnClick="Next_Click" runat="server" />
-
</form>
-
</body>
-
</html>
-
-
------------End My ASPX file ------------------------------
-
-
*************************************************
-
-------MY .VB Code AND CLASS begin--> Paging.vb --------------------
-
Imports System
-
Imports System.Data
-
Imports System.Data.SQLClient
-
Imports System.Web
-
Imports System.Web.UI
-
Imports System.Web.UI.Webcontrols
-
Imports System.Xml
-
-
-
namespace farhad
-
-
public class myfunction2 : Inherits Page
-
-
public pagedData As New pagedDataSource
-
public ds As New DataSet()
-
public strConnect As New SQLConnection("server=localhost;uid=sa;pwd=mysecretpass;Database=northwind")
-
public objSQLAdapter As New SQLDataAdapter("SELECT companyName, contactName, contactTitle FROM customers", strConnect)
-
public btnPrev AS LinkButton
-
public btnNext AS LinkButton
-
public pageNumber AS Label
-
public theDataList AS DataList
-
-
public Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
-
dopaging()
-
end sub
-
public function getTheData() As DataTable
-
-
objSQLAdapter.Fill(DS, "customers")
-
-
Return DS.Tables("customers").Copy
-
End function
-
-
public Sub doPaging()
-
pagedData.DataSource = getTheData().DefaultView
-
pagedData.AllowPaging = True
-
pagedData.PageSize = 5
-
-
Try
-
pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
-
Catch ex As Exception
-
pagedData.CurrentPageIndex = 0
-
End Try
-
-
btnPrev.Visible = ( NOT pagedData.IsFirstPage )
-
btnNext.Visible = ( NOT pagedData.IsLastPage )
-
-
pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount
-
-
theDataList.DataSource = pagedData
-
theDataList.DataBind()
-
End Sub
-
-
public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex - 1))
-
End Sub
-
-
public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
-
Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pagedData.CurrentPageIndex + 1))
-
End Sub
-
-
end class
-
end namespace
-
----------------------End My CLASS IN paging.VB FILE----------
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tobias Nilsson |
last post by:
I have almost exactly the same problem as the guy below.
Is it NOT possible running .NET code locally in Internet Explorer WITHOUT a
webserver????
/ Tobias
---------
My company has in the...
|
by: Daniel |
last post by:
Is this a bug in .net file io? is there a work around?
when writing a large file with using(StreamWriter ... if the network drive
of the share is removed then the file is never closed. I tried...
|
by: Nathan |
last post by:
I am working with a fellow developer on a small project. I started in
VB6, but after her C# training we decided to build the application in
..NET. Rather than rewrite the VB6 code, I continued in...
|
by: John Salerno |
last post by:
Do I need Web Developer (or anything else) to use ASP.NET, or can I
simply include some ASP.NET code in an html file? (As long as the server
has ASP.NET installed).
|
by: Naveen M |
last post by:
Hi,
We have an asp.net app that uploads and downloads files
files from an FTP server. It works this way.
1) Put a MyFile.request file on the server
2) server processes and returns MyFile.txt
3)...
|
by: Greg Collins [MVP] |
last post by:
I've got a web site I've built that uses an InfoPath form to generate an xml file. This file is then transformed within the default.aspx page to create the contents of the page.
The problem I'm...
|
by: noneya22 |
last post by:
I am building an asp.net 2.0 application and I need to be able to
convert existing FLV files on the server. Specifically, I need to be
able to take an FLV file and convert it to another,...
|
by: Sheena777 |
last post by:
I want to Play a specific sound file in my code when a certain event happens, but i don't know how. I can play the system sounds in my program and I know how to start the media player to play an mp3...
|
by: tharden3 |
last post by:
Hey all, I need some help with PHP code for paging my products on my site. I posted questions asking for help in the past, and was directed to this tutorial for help. The code that the tutorial gives...
|
by: maliksleo |
last post by:
Hi
my problem is that i want to generate a .aspx file at runtime using vb.net code
how is it possible help me
user will enter his code in the area provided and i wnat to generate the file having...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |