473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

sample code for pagination needed urgently in c#

nirmalsingh
218 100+
hi everybody,
as in ( the scripts) page below, i want to do some pagination in c#.
for example : <<previous>> 1 2 3 4 5 . . . . . 51 52 53 <<next>>
help me plz..

i have build htmltable using c# just like

Response.Write("<table">);
..........
..........
..........
Response.Write("</table">);

i want display only 10 records in a table, and also i know total number of records help me plz.
Jan 17 '07 #1
3 8474
radcaesar
759 Expert 512MB
Hi,
Here is a sample paging code in ASP 3.0, Conver the syntax to c#.

Why did u use HTML Table instead of DataGrid. Any particular reason ?

:)


<%
Option Explicit

Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001

Dim CONN_STRING
CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database.mdb")

Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim iFieldCount
Dim iRecordCount
Dim LoopRecordCount
Dim pageNum
Dim counter
Dim markShowPage
Dim I, J

iPageSize = 6

If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If

strSQL = "SELECT * from sample order by ID asc;"

Set objPagingConn = Server.CreateObject("ADODB.Connection")
objPagingConn.Open CONN_STRING

Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText

iPageCount = objPagingRS.PageCount
iFieldCount = objPagingRS.Fields.Count
iRecordCount = objPagingRS.RecordCount

If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1

If iPageCount = 0 Then
Response.Write "No records found!"
Else
objPagingRS.AbsolutePage = iPageCurrent

Dim arrDBData
ReDim arrDBData(iFieldCount, iRecordCount)
LoopRecordCount = 0

'arrDBData = objPagingRS.GetRows()

Do While LoopRecordCount < iPageSize And Not objPagingRS.EOF
For I = 0 To objPagingRS.Fields.Count - 1
arrDBData(I, LoopRecordCount) = objPagingRS.Fields(I)
Next
LoopRecordCount = LoopRecordCount + 1
objPagingRS.MoveNext
Loop

objPagingRS.Close
Set objPagingRS = Nothing
objPagingConn.Close
Set objPagingConn = Nothing
End If

iRecordCount = iRecordCount - 1
iFieldCount = iFieldCount - 1
LoopRecordCount = LoopRecordCount - 1

pageNum = Round(iRecordCount/iPageSize)
If pageNum < (iRecordCount/iPageSize) Then pageNum = pageNum + 1

Response.Write "&nbsp;&nbsp;<b>Page: "
For counter = 1 To pageNum
if counter=iPageCurrent then
Response.Write "&nbsp;<span class=activepage>&nbsp;"
Response.Write counter
Response.Write "&nbsp;</span>"
markShowPage=1
else
Response.Write "&nbsp;<a onclick=exitoff() href=db_paging_array.asp?page="
Response.Write counter
Response.Write " class=listingLink>"
Response.Write counter
Response.Write "</a>"
end if
Next
Response.Write "</b>"

Response.Write "&nbsp;&nbsp;"

Response.Write "<b>"

Response.Write "<a href=db_paging_array.asp?page="
If iPageCurrent = 1 Then
Response.Write pageNum
else
Response.Write iPageCurrent-1
end if
Response.Write " class=listingLink>Back</a>&nbsp;&nbsp;"
Response.Write "<a href=db_paging_array.asp?page="
If iPageCurrent = pageNum Then
Response.Write "1"
else
Response.Write iPageCurrent+1
end if
Response.Write " class=listingLink>Next</a>"

Response.Write "</b>"

%>
<p>

<table border="1">
<%
For I = 0 To LoopRecordCount
Response.Write "<tr>" & vbCrLf
For J = 0 To ifieldCount
Response.Write vbTab & "<td>" & arrDBData(J, I) & "</td>" & vbCrLf
Next ' J
Response.Write "</tr>" & vbCrLf
Next ' I
%>
</table>


<style>

body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}

td {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}

listingLink {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: blue;
text-decoration:none;
margin-left:0px;
margin-right:0px;
}

a.listingLink:hover {
color:#FF0000;
}

activepage {
color:#ffffee;
background-color: #000033;
font-weight: bold;
}
</style>



hi everybody,
as in ( the scripts) page below, i want to do some pagination in c#.
for example : <<previous>> 1 2 3 4 5 . . . . . 51 52 53 <<next>>
help me plz..

i have build htmltable using c# just like

Response.Write("<table">);
..........
..........
..........
Response.Write("</table">);

i want display only 10 records in a table, and also i know total number of records help me plz.
Jan 17 '07 #2
nirmalsingh
218 100+
i am loading radio buttons in the first column of every rows, and someone says client side control will be loaded more faster then web controls, i am starter to .net. is there is any way to load controls in datagrid? if s give sample code for reference plz
Jan 17 '07 #3
radcaesar
759 Expert 512MB
Yes thats true. But that will not affect the application's performance like you think. I will suggest the datagrid for this purpose.

After you add the controls like this, refering that particular control will lead you with lot of work arounds. When compared to the same, datagrid is preferable.

:)

i am loading radio buttons in the first column of every rows, and someone says client side control will be loaded more faster then web controls, i am starter to .net. is there is any way to load controls in datagrid? if s give sample code for reference plz
Jan 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
0
by: Kamliesh Nadar | last post by:
Hi I am developing a software using VB.NET I am facing following problems - 1. Though I have placed the NotifyIcon control on the window service application, after starting the service I am...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
5
by: John | last post by:
Hi I am developing a vb2005/sql server 2005 winform app which involves displaying records in a list, one page at a time. The total number of records is large. I am wondering if there is a way...
1
by: dhanu | last post by:
How to manage pagination in AJAX? My requirement is similar to GMails inbox feature. Whenever a new mail comes in,the newly arrived mail is at the start of my inbox and last row in that page...
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
1
nirmalsingh
by: nirmalsingh | last post by:
hi everybody, as in ( the scripts) page below, i want to do some pagination in javascript. for example : <<previous>> 1 2 3 4 5 . . . . . 51 52 53 <<next>> help me plz..
2
by: adamjblakey | last post by:
Hi, I currently use this for extracting data from my DB. $new = new database; $new->selects("SELECT * FROM table"); $result = $new->getRes(); $countrows = $new->countrows();
1
by: Robert Wells | last post by:
Gentlemen, We are looking for two IBM documents that are needed urgently for a project. They are titled "4680 Store Systems Serial I/O Channel Attachment Information" and "Serial I/O Product...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.