1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before...
-
Upload
lindsay-douglas -
Category
Documents
-
view
223 -
download
0
description
Transcript of 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before...
![Page 2: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/2.jpg)
2
Master Page
• All Web pages will be similar• Should be created before other web pages• Add New Items• Controls on the Master page ContentPlaceHolder Leave ContentPlaceHolder empty Add controls before ContentPlaceHolder• Adding a label• Adding a TreeView
![Page 3: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/3.jpg)
3
TreeView Controls
• Navigation Tab• Property Nodes (Collection)
– Root Nodes– Child Nodes– Node Properties Text NagivateUrl (Can be set later)
![Page 4: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/4.jpg)
4
Content Page
• Should be created after master page• Check Select Master Page• Adding controls inside ContentPlaceHolder
![Page 5: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/5.jpg)
5
TreeView on Master Page
• Creating master page• Adding TreeView control• Setting TreeView properties, but not NagivateUrl• Creating content pages• Setting NagivateUrl of TreeView on master page
![Page 6: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/6.jpg)
Navigating all pages of Lab 3
6
![Page 7: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/7.jpg)
ASP.NET Folders
• Solution Explorer• Right click Web site• Add ASP.NET Folder• App_Code• App_Data• . . .
7
![Page 8: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/8.jpg)
8
Accessing Database
![Page 9: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/9.jpg)
9
Database File
• UWPCS3870.accdb
• How to upload data file Right click Apps_Data folder Select Add An Existing Item
![Page 10: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/10.jpg)
10
Accessing Database
• Data Controls– SqlDataSource– AccessDataSource– . . .
• Code class– Connection– Command– DataAdpater – AdapterBuilder
![Page 11: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/11.jpg)
DataClass
• Code class in folder App_Code• No code module• All variables and procedures should be Shared• Otherwise, need to create object
11
![Page 12: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/12.jpg)
Variables
Private Const ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0; ” & _ “Data Source=|DataDirectory|\UWPCS3870.accdb"
Private Shared prodAdapter As System.Data.OleDb.OleDbDataAdapterPrivate Shared prodBuilder As System.Data.OleDb.OleDbCommandBuilderPrivate Shared prodCmd As New Data.OleDb.OleDbCommandPrivate Shared con As New Data.OleDb.OleDBConnection
Public Shared tblProduct As New Data.DataTable
The objects are available all the time.
12
![Page 13: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/13.jpg)
Setup Command and Adapter‘ Sets up the connection, command and adapterPublic Shared Sub setupAdapter() con.ConnectionString = ConStr
prodCmd.Connection = con prodCmd.CommandType = Data.CommandType.Text prodCmd.CommandText = "Select * from Product order by ProductID" prodAdapter = New System.Data.OleDb.OleDbDataAdapter(prodCmd)
End Sub
13
![Page 14: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/14.jpg)
Retrieve Data Records
‘ Gets the table records and the table schemaPublic Shared Sub getAllProdcts() ‘ Need to reset the command prodCmd.CommandText = "Select * from Product order by ProductID"
prodAdapter.Fill(tblProduct) prodAdapter.FillSchema(tblProduct, Data.SchemaType.Source)End Sub
14
![Page 15: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/15.jpg)
Calling Subs in DataClass and Binding Gridview
Protected Sub Page_Load(. . .) Handles Me.Load DataClass.setup() DataClass.getAllProducts()
GridView1.DataSource = DataClass.tblProducts GridView1.DataBind()End Sub
Refill the data table for each page request.
15
![Page 16: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/16.jpg)
Processing of Dynamic Web Pages
• Build Web Site: Compiling code-behind classes to a DLL file No exe file• ASP.NET instantiates class objects• ASP.NET processes the class object• ASP.NET generates a page• IIS accepts page requests and sends the
generated pages back to client16
![Page 17: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/17.jpg)
Page ShoppingTextchanged event of Textbox txtID
id = txtID.Text.Trimindex = -1
For x = 0 To DataClass.tblProducts.Rows.Count - 1 If DataClass.tblProducts.Rows(x)(0) = id Then index = x Exit For End IfNext
If index <> -1 Then txtName.Text = DataClass.tblProducts.Rows(index)(1)
17
![Page 18: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/18.jpg)
Page Shopping
Textchanged event of Textbox txtID
id = txtID.Text.Trim
Dim row as Data.DataRow
row = DataClass.tblProducts.Rows.Find(id)
If row Is Nothing Then ‘ not foundElse ‘ FoundEnd If
18
![Page 19: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/19.jpg)
Page Shopping
Property AutoPastBack of Textbox
Must be True to fire Textchanged event
19
![Page 20: 1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.](https://reader036.fdocuments.net/reader036/viewer/2022082620/5a4d1b007f8b9ab059986411/html5/thumbnails/20.jpg)
Page ShoppingTextchanged event of Textbox txtQuanity
20