|
The web Form design,
web_search.aspx
Create Visual C# .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_VCnet 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_VCnet\Web_VCnetmdb
- 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 C#
.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 ...
|
|
using
System; using
System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
namespace Web_VCnet
{
///
<summary>
///
Summary description for Web_search.
///
</summary>
public
class
Web_search : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.DataGrid DataGrid1;
protected
System.Web.UI.WebControls.Label linfo_search2;
protected
System.Web.UI.WebControls.Label linfo_search1;
protected
System.Web.UI.WebControls.TextBox TextBox4;
protected
System.Web.UI.WebControls.TextBox TextBox3;
protected
System.Web.UI.WebControls.Label Label2;
protected
System.Web.UI.WebControls.Label lbmessage;
protected
System.Web.UI.WebControls.Button btn_search;
protected
System.Web.UI.WebControls.TextBox txtsearch;
protected
System.Web.UI.WebControls.Label Label_search1;
protected
System.Web.UI.WebControls.Label Label_shearch2;
protected
System.Web.UI.WebControls.Label lsearch;
protected
System.Web.UI.WebControls.TextBox TextBox1;
protected
System.Web.UI.WebControls.TextBox TextBox5;
protected
System.Web.UI.WebControls.Panel Panel1;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Data.OleDb.OleDbConnection OleDbConnection1;
protected
System.Web.UI.WebControls.HyperLink HyperLink1;
//variables
System.Data.OleDb.OleDbCommand
vcmdnext;
string
vsearch_text;
int
CurrentPage;
int
totalrecords;
private
void
Page_Load(object
sender, System.EventArgs e)
{
// Put user
code to initialize the page here
}
Web Form Designer generated
code |
private void
btn_search_Click(object
sender, System.EventArgs e)
{
if (this.txtsearch.Text.Length
> 0)
{
this.DataGrid1.Visible = true;
lbmessage.Visible =
false;
vsearch_text =
this.txtsearch.Text.Trim().ToLower();
this.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)
{
FillGrid(vcmdnext);
}
else
{
this.DataGrid1.Visible = false;
}
return;
}
else
{
this.DataGrid1.Visible = false;
//fore color
font, navy and bold
this.linfo_search1.Visible = false;
this.linfo_search2.Visible = false;
lbmessage.Visible =
true;
lbmessage.Text = " ... Type
first, the search word ... ";
}
}
//System.Data.OleDb
- Search, Total Found records
private void
sub_infosearch( string
vsearchtext)
{
System.Data.OleDb.OleDbCommand
vselect;
System.Data.OleDb.OleDbDataAdapter vda;
System.Data.DataSet vdset;
string
wheresearch;
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
System.Data.DataSet();
vselect.Connection =
this.OleDbConnection1;
vdset.EnforceConstraints =
false;
try
{
this.OleDbConnection1.Open();
vda.Fill(vdset, "Categories");
}
catch
(System.Exception eLoad)
{
this.Response.Write(eLoad.Message);
}
vdset.EnforceConstraints =
true;
this.OleDbConnection1.Close();
totalrecords =
vdset.Tables["Categories"].Rows.Count;
if
(vdset.Tables["Categories"].Rows.Count > 0)
{
this.linfo_search1.Visible = true;
this.linfo_search1.Text
= "* Search Criteria: " + vsearch_text + ", Total Found:
" + totalrecords.ToString() + " records";
this.linfo_search2.Visible = true;
this.linfo_search2.Text
= "* 1 - " + totalrecords.ToString() + " shown below";
}
else
{
this.linfo_search1.Visible = true;
this.linfo_search1.Text
= "Search Criteria: " + vsearch_text + ", Total Found: "
+ totalrecords.ToString() + " records";
this.linfo_search2.Visible = true;
this.linfo_search2.Text
= "0 shown below";
}
}
public void
FillGrid(System.Data.OleDb.OleDbCommand currentCommand)
{
System.Data.OleDb.OleDbDataReader dr;
this.OleDbConnection1.Open();
dr =
currentCommand.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
dr.Close();
this.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.
}
//Select
command - System.Data.OleDb.OleDbCommand
private void
sub_search(string
vsearchtext)
{
string
wheresearch;
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 =
this.OleDbConnection1;
vcmdnext.Parameters.Add( new
System.Data.OleDb.OleDbParameter("@categoryID",
System.Data.OleDb.OleDbType.Integer, 4, "Categoryid"));
}
}
} | | |
|
|