|
The web Form design,
web_search.aspx
Create Visual Basic .Net Forn - web_search.aspx
Classes used in this
Form: OleDbConnection, Panel,
HyperLink, Button, DataGrid, TextBox,
Label
Create
the Web Form page
- On the Project menu ,
click Add New Item ...
- In the Add New
Item - Web_VBnet dialog box:
- In the
Categories pane, select Local Project
Items
- In the Templates
pane, select Web form . A message
appears - (a form for Web Applications).
- In the Name
box, type web_search.aspx
- Click
Open
|
 |
- In the Web
Forms Designer appears the empty Web Form
design
|
|
|
1. |
The
web_search.aspx
design |
|
 |
Document
Properties.. |
| |
3. |
From the Toolbox add these
controls .... 1
OleDbConnection contol,
1 Panel contol,
1
HyperLink contol,
1 Button contol,
1 DataGrid contol,
4 TextBox contols,
7 Label contols
|
|
- Add the OleDbConnection
control - OleDbConnection1, OleDbConnection
Properties:
Name: ConnectionString: |
OleDbConnection1 Jet
OLEDB:Global Partial
.... |
|
Note: Connection info
:
Provider =
Microsoft.Jet.OLEDB.4.0
Data source =
...:\Web_VBnet\Web_VBnetmdb
- Add the Panel
control - Panel1, Panel
Properties:
(ID): BackColor:
Width: |
Panel1
Olive
877px |
|
- Add the HyperLink
control - HyperLink2, HyperLink
Properties:
(ID): NavigateUrl:
Text: |
HyperLink2
WebForm1.aspx
return
to main |
|
- Add the Button
control - Button1, Button
Properties:
- Add the DataGrid
control - DataGrid1, DataGrid
Properties:1
(ID):
SataKeyField:
DataMember:
DataSource: PageSize: |
DataGrid1
5 | |
- Add 4 TextBox
control - CalcField
Properties:
-
txtsearch, TextBox Proprieties
- TextBox2
- Text:
Soft drinks
-
TextBox3
- Text:
coffees and fish
-
TextBox4
- Text:
coffees
|
- Add 7 Label
controls
-
Label1 , Label
Properties
(ID): Font: Text: |
Label1
Rockwell Extra Bold, X-Large Main, Web Form
Page - Visual Basic .Net | |
-
linfo_search1
-
link_search2
-
Label_search1
-
linfo_search2
-
lsearch
-
Label2
| | | |
|
web_search.aspx file, the codes after modification
...
The text
Code
is red color, the codes added manuel ... |
|
Public
Class
Web_search
Inherits System.Web.UI.Page
'Variables
Dim vcmdnext As
System.Data.OleDb.OleDbCommand ' Select command
Dim vsearch_text
As String
Dim CurrentPage
As Integer
Dim totalrecords
As Integer
Protected
WithEvents
lbmessage As
System.Web.UI.WebControls.Label
Web Form Designer generated
code |
Private
Sub
Page_Load(ByVal
sender As
System.Object, ByVal
e As
System.EventArgs)
Handles
MyBase.Load
'Put user code to
initialize the page here
End
Sub
Private Sub
btn_search_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
btn_search.Click
If
Me.txtsearch.Text.Length > 0 Then
Me.DataGrid1.Visible = True
lbmessage.Visible = False
vsearch_text = Me .txtsearch.Text.Trim.ToLower
Me.txtsearch.Text
= ""
'System.Data.OleDb.OleDbCommand
- Search, Total Found records
sub_infosearch(vsearch_text)
'search, Select
command - System.Data.OleDb.OleDbCommand
sub_search(vsearch_text)
vcmdnext.Parameters("@categoryID").Value
= 0
CurrentPage = 0
If totalrecords >
0 Then
FillGrid(vcmdnext)
Else
Me.DataGrid1.Visible = False
End If
Exit Sub
Else
Me.DataGrid1.Visible = False
'fore color font,
navy and bold
Me.linfo_search1.Visible = False
Me.linfo_search2.Visible = False
lbmessage.Visible = True
lbmessage.Text = " ... Type
first, the search word ... "
End If
End Sub
'System.Data.OleDb
- Search, Total Found records
Private Sub
sub_infosearch(ByVal vsearchtext As String)
Dim vselect As
System.Data.OleDb.OleDbCommand ' Select command
Dim vda As
System.Data.OleDb.OleDbDataAdapter ' Dataadapter
Dim vdset As
System.Data.DataSet
Dim wheresearch
As String
Dim vval As
Integer
wheresearch = " WHERE (InStr(LCase(Description),
'" & vsearchtext & "') > 0)"
vselect =
New
System.Data.OleDb.OleDbCommand("SELECT CategoryID,
CategoryName, Description FROM Categories " & wheresearch
& " ORDER BY CategoryID")
vda =
New
System.Data.OleDb.OleDbDataAdapter(vselect)
vdset =
New
DataSet
vselect.Connection() =
Me.OleDbConnection1
' Select command
vdset.EnforceConstraints = False
Try
'Open the
connection.
Me.OleDbConnection1.Open()
vda.Fill(vdset, "Categories")
Catch
fillException As
System.Exception
Me.Response.Write(fillException.Message)
Finally
vdset.EnforceConstraints = True
Me.OleDbConnection1.Close()
End Try
totalrecords =
vdset.Tables("Categories").Rows.Count
If
vdset.Tables("Categories").Rows.Count > 0 Then
Me.linfo_search1.Visible = True
Me.linfo_search1.Text
= "* Search Criteria: " + vsearch_text + ", Total Found: "
+ totalrecords.ToString + " records"
Me.linfo_search2.Visible = True
Me.linfo_search2.Text
= "* 1 - " + totalrecords.ToString + " shown below"
Else
Me.linfo_search1.Visible = True
Me.linfo_search1.Text
= "Search Criteria: " + vsearch_text + ", Total Found: " +
totalrecords.ToString + " records"
Me.linfo_search2.Visible = True
Me.linfo_search2.Text
= "0 shown below"
End If
End Sub
Private Sub
FillGrid(ByVal currentCommand As
System.Data.OleDb.OleDbCommand)
Dim dr As
System.Data.OleDb.OleDbDataReader
Me.OleDbConnection1.Open()
dr = currentCommand.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
dr.Close()
Me.OleDbConnection1.Close()
ViewState("CurrentPage") =
CurrentPage
ViewState(CurrentPage.ToString())
= DataGrid1.Items(0).Cells(0).Text
' Determine how
many rows were filled into the grid. If it is less
' than the number
of rows per page, there are no more rows in the
' table, and the
Next button should be disabled.
End Sub
'Select command -
System.Data.OleDb.OleDbCommand
Private Sub
sub_search(ByVal vsearchtext As String)
Dim wheresearch
As String
wheresearch = " WHERE ((InStr(LCase(Description),
'" & vsearchtext & "') > 0) and (CategoryID > @categoryID))"
vcmdnext =
New
System.Data.OleDb.OleDbCommand("SELECT CategoryID,
CategoryName, Description FROM Categories " & wheresearch
& " ORDER BY CategoryID")
vcmdnext.Connection =
Me.OleDbConnection1
vcmdnext.Parameters.Add( New
System.Data.OleDb.OleDbParameter("@categoryID",
System.Data.OleDb.OleDbType.Integer, 4, "Categoryid"))
End Sub
End
Class | | |
|
|