473,715 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sample code for pagination needed urgently in c#

nirmalsingh
218 New Member
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 8489
radcaesar
759 Recognized Expert Contributor
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=Micro soft.Jet.OLEDB. 4.0; Data Source=" & Server.MapPath( "database.m db")

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.QuerySt ring("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.Qu eryString("page "))
End If

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

Set objPagingConn = Server.CreateOb ject("ADODB.Con nection")
objPagingConn.O pen CONN_STRING

Set objPagingRS = Server.CreateOb ject("ADODB.Rec ordset")
objPagingRS.Pag eSize = iPageSize
objPagingRS.Cac heSize = iPageSize
objPagingRS.Ope n strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText

iPageCount = objPagingRS.Pag eCount
iFieldCount = objPagingRS.Fie lds.Count
iRecordCount = objPagingRS.Rec ordCount

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

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

Dim arrDBData
ReDim arrDBData(iFiel dCount, iRecordCount)
LoopRecordCount = 0

'arrDBData = objPagingRS.Get Rows()

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

objPagingRS.Clo se
Set objPagingRS = Nothing
objPagingConn.C lose
Set objPagingConn = Nothing
End If

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

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

Response.Write "&nbsp;&nbsp;<b >Page: "
For counter = 1 To pageNum
if counter=iPageCu rrent then
Response.Write "&nbsp;<spa n class=activepag e>&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=listingLi nk>"
Response.Write counter
Response.Write "</a>"
end if
Next
Response.Write "</b>"

Response.Write "&nbsp;&nbs p;"

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=listingLi nk>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=listingLi nk>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:h over {
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 New Member
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 Recognized Expert Contributor
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
3403
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
1466
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 not able to view the icon on the system tray. 2. Secondly how to add a new item in the Window explorer
1
5813
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
5
1264
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 either in vb/ado or sql server that automatically pages a certain number of records at a time and when user scrolls down (or up) pages the next set of records? I guess I can possibly program it manually but it may be complicated specially when the...
1
7408
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 goes to next page(ie Pagination happens automatically without any page refresh). I have used ajaxdisplay tag library from Source Forge which does pagination but doesnot suffice my requirement.ie Whenever a new record is added then it should also be...
4
3646
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 and reaches a specific length, it terminates printing that page, prints a page number, and then begins to print the next page using the same header and format as the previous page. The page uses no tables or paragraph elements, only CSS. IOW, I...
1
5169
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
1124
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
1463
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 Attachment Information". $100 will be paid to the first person to deliver either or both of these documents in their entirety. If you have partial documents or you are not sure please contact US anyway. The contact person is ty@rocketfarm.com ...
0
8715
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9322
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9093
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6641
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4472
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4734
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.