I have created an ASP.NET page that allows the user to page through a result
set. I need to expand on this. On that same page I a filed where the user can
type in a search string. When they click a button ALL the results will be
returned and the closest match to the search string will be highlighted. The
approach I am taking to page the data is to put the keys/indexes into an
array then create another data reader based on those results to display the
actual data. There may be a better way, if there are any suggestions.
Bottom line I need to find what page the search string is on so I can
highlight it. I guess I would have to calculate what page that record is on,
but I can’t wrap my head around it. Here is some code that I use for the
paging:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load
Dim Conn As SqlConnection
Dim Query As String
Dim SqlComm As SqlCommand
Dim myDataReader As SqlDataReader
' Define connection object
Conn = New SqlConnection(C onnString)
' Define query to retrieve primary key values
Query = "SELECT " & PrimaryKeyColum n & " FROM " & TableName & "
WHERE (Categories.Cat egoryName <= 'Confections') ORDER BY " & SetSorting()
' Define command object
SqlComm = New SqlCommand(Quer y, Conn)
' Open connection to database
Conn.Open()
' Create DataReader
myDataReader = SqlComm.Execute Reader()
' Iterate through records and add to array list
While myDataReader.Re ad()
IDList.Add(myDa taReader(Primar yKeyColumn))
End While
' Close DataReader and connection objects
myDataReader.Cl ose()
myDataReader = Nothing
Conn.Close()
Conn = Nothing
' If page has not been posted back, retrieve first page of records
If Not Page.IsPostBack Then
Paging()
End If
End Sub
Sub Paging(Optional ByVal WhichPage As Integer = 1, Optional ByVal
RecordsPerPage As Integer = 10)
' Determine total number of records
Dim NumItems As Integer = IDList.Count
' Set number of records per page
Dim PageSize As Integer = RecordsPerPage
' Determine number of pages minus any leftover records
Dim Pages As Long = NumItems \ PageSize
' Save this number for future reference
Dim WholePages As Long = NumItems \ PageSize
' Determine number of leftover records
Dim Leftover As Integer = NumItems Mod PageSize
' If there are leftover records, increase page count by one
If Leftover > 0 Then
Pages += 1
End If
Dim i As Integer
Dim CurrentSelectio n As String
Dim StartOfPage As Integer
Dim EndOfPage As Integer
' Set current page
Dim CurrentPage As Integer = WhichPage
' If current page does not fall within the valid range of pages
If CurrentPage > Pages Or CurrentPage < 0 Then
' Call paging subroutine and reset to first page
Paging(1, RecordsPerPage)
' If current page does fall within valid range of pages
Else
' If current page is the last page, hide the "next" and "last"
navigation links
If CurrentPage = Pages Then
NextLink.ImageU rl = "images/Nav_Next_Disabl ed.jpg"
NextLink.Enable d = False
LastLink.ImageU rl = "images/Nav_LastPage_Di sabled.jpg"
LastLink.Enable d = False
' Otherwise, show the "next" and "last" navigation links and
set the page index each will pass when clicked
Else
NextLink.ImageU rl = "images/Nav_Next.jpg"
NextLink.Enable d = True
LastLink.ImageU rl = "images/Nav_LastPage.jp g"
LastLink.Enable d = True
NextLink.Comman dArgument = CurrentPage + 1
LastLink.Comman dArgument = Pages
End If
' If current page is the first page, hide the "first" and
"previous" navigation links
If CurrentPage = 1 Then
PreviousLink.Im ageUrl = "images/Nav_Previous_Di sabled.jpg"
PreviousLink.En abled = False
FirstLink.Image Url = "images/Nav_Firstpage_D isabled.jpg"
FirstLink.Enabl ed = False
' Otherwise, show the "first" and "previous" navigation
links and set the page index each will pass when clicked
Else
PreviousLink.Im ageUrl = "images/Nav_Previous.jp g"
PreviousLink.En abled = True
FirstLink.Image Url = "images/Nav_FirstPage.j pg"
FirstLink.Enabl ed = True
PreviousLink.Co mmandArgument = CurrentPage - 1
FirstLink.Comma ndArgument = 1
End If
' Create ArrayList to store range of valid pages
Dim JumpPageList = New ArrayList
Dim x As Integer
' Iterate through range of valid pages and add to ArrayList
For x = 1 To Pages
JumpPageList.Ad d(x)
Next
' Use this ArrayList to populate page navigation drop-down menu
JumpPage.DataSo urce = JumpPageList
JumpPage.DataBi nd()
' Select current page in drop-down menu
JumpPage.Select edIndex = CurrentPage - 1
' Set the record count and page count text
RecordCountLabe l.Text = NumItems
PageCountLabel. Text = Pages
' Determine the starting and ending index in the IDList
ArrayList given the current page
StartOfPage = PageSize * (CurrentPage - 1)
EndOfPage = Min((PageSize * (CurrentPage - 1)) + (PageSize - 1),
((WholePages * PageSize) + Leftover - 1))
' Retrieve the subset of primary key values that belong on the
current page
Dim CurrentSubset As String = Join(IDList.Get Range(StartOfPa ge,
(EndOfPage - StartOfPage + 1)).ToArray, ",")
Dim Conn As SqlConnection
Dim Query As String
Dim SqlComm As SqlCommand
' Define connection object
Conn = New SqlConnection(C onnString)
' Define query to retrieve current page's records
Query = "SELECT " & ColumnsToRetrie ve & " FROM " & TableName & "
WHERE " & PrimaryKeyColum n & " IN ('" & CurrentSubset.R eplace(",", "','") &
"') ORDER BY " & SetSorting()
' Define command object
SqlComm = New SqlCommand(Quer y, Conn)
' Open connection
Conn.Open()
' Databind records to repeater
myRepeater.Data Source = SqlComm.Execute Reader()
myRepeater.Data Bind()
' Close connection
Conn.Close()
Conn = Nothing
End If
End Sub 2 2438
Daniel Di Vita wrote: I have created an ASP.NET page
There was no way for you to know it (except maybe by browsing through some
of the previous questions before posting yours - always a recommended
practice), but this is a classic asp newsgroup.
ASP.Net is a different technology from classic ASP.
While you may be lucky enough to find a dotnet-savvy person here who can
answer your question, you can eliminate the luck factor by posting your
question to a newsgroup where the dotnet-savvy people hang out. I suggest
microsoft.publi c.dotnet.framew ork.aspnet.
that allows the user to page through a result set. I need to expand on this.
There are a couple articles by Scott Mitchell that deal with this topic: http://aspnet.4guysfromrolla.com/articles/031506-1.aspx
On that same page I a filed where the user can type in a search string. When they click a button ALL the results will be returned and the closest match to the search string will be highlighted. The approach I am taking to page the data is to put the keys/indexes into an array then create another data reader based on those results to display the actual data. There may be a better way, if there are any suggestions.
There's a lot to digest there, and frankly, I'm not sure what the problem
is. You may benefit by reading Erland Sommarskog's dynamic search conditions
article: http://www.sommarskog.se/dyn-search.html
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
"Daniel Di Vita" <Da**********@d iscussions.micr osoft.com> wrote in message
news:50******** *************** ***********@mic rosoft.com... I have created an ASP.NET page that allows the user to page through a
result
This group is for classic ASP. Direct questions regarding ASP.NET to
microsoft.publi c.dotnet.framew ork.aspnet[.*] newsgroups.
set. I need to expand on this. On that same page I a filed where the user
can type in a search string. When they click a button ALL the results will be returned and the closest match to the search string will be highlighted.
The approach I am taking to page the data is to put the keys/indexes into an array then create another data reader based on those results to display
the actual data. There may be a better way, if there are any suggestions.
Bottom line I need to find what page the search string is on so I can highlight it. I guess I would have to calculate what page that record is
on, but I can't wrap my head around it. Here is some code that I use for the paging:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim Conn As SqlConnection Dim Query As String Dim SqlComm As SqlCommand Dim myDataReader As SqlDataReader
' Define connection object Conn = New SqlConnection(C onnString)
' Define query to retrieve primary key values Query = "SELECT " & PrimaryKeyColum n & " FROM " & TableName & " WHERE (Categories.Cat egoryName <= 'Confections') ORDER BY " & SetSorting()
' Define command object SqlComm = New SqlCommand(Quer y, Conn)
' Open connection to database Conn.Open()
' Create DataReader myDataReader = SqlComm.Execute Reader()
' Iterate through records and add to array list While myDataReader.Re ad() IDList.Add(myDa taReader(Primar yKeyColumn)) End While
' Close DataReader and connection objects myDataReader.Cl ose() myDataReader = Nothing Conn.Close() Conn = Nothing
' If page has not been posted back, retrieve first page of records If Not Page.IsPostBack Then Paging() End If
End Sub
Sub Paging(Optional ByVal WhichPage As Integer = 1, Optional ByVal RecordsPerPage As Integer = 10)
' Determine total number of records Dim NumItems As Integer = IDList.Count
' Set number of records per page Dim PageSize As Integer = RecordsPerPage
' Determine number of pages minus any leftover records Dim Pages As Long = NumItems \ PageSize
' Save this number for future reference Dim WholePages As Long = NumItems \ PageSize
' Determine number of leftover records Dim Leftover As Integer = NumItems Mod PageSize
' If there are leftover records, increase page count by one If Leftover > 0 Then Pages += 1 End If
Dim i As Integer Dim CurrentSelectio n As String Dim StartOfPage As Integer Dim EndOfPage As Integer
' Set current page Dim CurrentPage As Integer = WhichPage
' If current page does not fall within the valid range of pages If CurrentPage > Pages Or CurrentPage < 0 Then
' Call paging subroutine and reset to first page Paging(1, RecordsPerPage)
' If current page does fall within valid range of pages Else
' If current page is the last page, hide the "next" and "last" navigation links If CurrentPage = Pages Then NextLink.ImageU rl = "images/Nav_Next_Disabl ed.jpg" NextLink.Enable d = False
LastLink.ImageU rl = "images/Nav_LastPage_Di sabled.jpg" LastLink.Enable d = False
' Otherwise, show the "next" and "last" navigation links
and set the page index each will pass when clicked Else
NextLink.ImageU rl = "images/Nav_Next.jpg" NextLink.Enable d = True
LastLink.ImageU rl = "images/Nav_LastPage.jp g" LastLink.Enable d = True NextLink.Comman dArgument = CurrentPage + 1 LastLink.Comman dArgument = Pages
End If
' If current page is the first page, hide the "first" and "previous" navigation links If CurrentPage = 1 Then
PreviousLink.Im ageUrl = "images/Nav_Previous_Di sabled.jpg" PreviousLink.En abled = False
FirstLink.Image Url = "images/Nav_Firstpage_D isabled.jpg" FirstLink.Enabl ed = False ' Otherwise, show the "first" and "previous" navigation links and set the page index each will pass when clicked Else
PreviousLink.Im ageUrl = "images/Nav_Previous.jp g" PreviousLink.En abled = True
FirstLink.Image Url = "images/Nav_FirstPage.j pg" FirstLink.Enabl ed = True
PreviousLink.Co mmandArgument = CurrentPage - 1 FirstLink.Comma ndArgument = 1
End If
' Create ArrayList to store range of valid pages Dim JumpPageList = New ArrayList
Dim x As Integer
' Iterate through range of valid pages and add to ArrayList For x = 1 To Pages JumpPageList.Ad d(x) Next
' Use this ArrayList to populate page navigation drop-down
menu JumpPage.DataSo urce = JumpPageList JumpPage.DataBi nd()
' Select current page in drop-down menu JumpPage.Select edIndex = CurrentPage - 1
' Set the record count and page count text RecordCountLabe l.Text = NumItems PageCountLabel. Text = Pages
' Determine the starting and ending index in the IDList ArrayList given the current page StartOfPage = PageSize * (CurrentPage - 1) EndOfPage = Min((PageSize * (CurrentPage - 1)) + (PageSize -
1), ((WholePages * PageSize) + Leftover - 1))
' Retrieve the subset of primary key values that belong on the current page Dim CurrentSubset As String =
Join(IDList.Get Range(StartOfPa ge, (EndOfPage - StartOfPage + 1)).ToArray, ",")
Dim Conn As SqlConnection Dim Query As String Dim SqlComm As SqlCommand
' Define connection object Conn = New SqlConnection(C onnString)
' Define query to retrieve current page's records Query = "SELECT " & ColumnsToRetrie ve & " FROM " & TableName &
" WHERE " & PrimaryKeyColum n & " IN ('" & CurrentSubset.R eplace(",", "','")
& "') ORDER BY " & SetSorting()
' Define command object SqlComm = New SqlCommand(Quer y, Conn) ' Open connection Conn.Open()
' Databind records to repeater myRepeater.Data Source = SqlComm.Execute Reader() myRepeater.Data Bind()
' Close connection Conn.Close() Conn = Nothing
End If
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: leegold2 |
last post by:
I've seen previous threads but I still need help in highlighting
search terms like google does on their search result page.
I know I need, ob_start();
Then I process to highlight the search term hits, then I flush the
buffer to render the page.
I'm comfortable with PHP coding but what I need is simple step by step
help, with a simple search form example.
The explanations I see are either way to lofty or too small a piece of
|
by: Chris Stromberger |
last post by:
When issuing updates in mysql (in the console window), mysql will tell
you if any rows matched and how many rows were updated (see below). I
know how to get number of rows udpated using MySQLdb, but is there any
way to get the number of rows matched? I want to find out, when rows
updated = 0, if there were no updates because the row wasn't found
(rows matched will = 0) or because the update would not have changed
any data (rows matched =...
|
by: David Morgan |
last post by:
Hello
I have a little function to highlight text if it exists.
Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = vFind
RegEx.IgnoreCase = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
|
by: Jim Moseby |
last post by:
I stumbled across this while trying to update a table with a timestamp type column. At the time, I didn't know that the timstamp column would update itself when a row was changed. A kind gentleman in another group pointed that out to me.
I added a column to a table and wanted to update the rows to populate the new column. When doing something like this I usually will create a temporary table and perform a dry run, just to make sure I am...
|
by: David Smithz |
last post by:
Hi,
If you run a query which has a WHERE statement in which has a few
possibilities separated OR statements, e.g.
Select * from table where (Afield = 2) OR (Bfield = 2) OR (Cfield = 2)
In the returned results is it possible to know what particular part of the
WHERE clause a field matched.
| |
by: shantibhushan |
last post by:
Hi buddy
I have to highlight search text from search results as it is in google or alibaba.com.
e.g. if I input paper as a searchtext in search results paper word should be highlighted. as it isin google help.
some one help me please.
I am working in asp.net2.0 using c#
Regards,
|
by: toffee |
last post by:
Hi all,
I have a table with 12 cols and 10 rows. When a user clicks on a table cell;
the page is refreshed and displays some data below the table dependant on
whichever cell was selected.
I would like to make it so that whichever cell was clicked; the background
color is changed - so that when the user sees the data, (s)he can tell which
cell it relates to.
Does anyone know of a clever way to do this ?
|
by: Celeste |
last post by:
Hello,
I'm trying to parse the referring url for google search terms so that when this page loads it will scroll to and highlight the search term(s). Should i be using document.referrer?
Please take a look at my code and tell me what i'm doing wrong:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>highlight</title>
|
by: Mel |
last post by:
I have a treeview control that contains a list of filenames which I am
searching. If a file in the tree matches the search criteria the
entire node is expanded. Often times there are other files in that
expanded node that don't match the criteria. Is there a way to
highlight ALL the nodes that matched the search criteria?
Example Code (Using ASP.NET 2.0, Visual Basic):
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| | |