Download presentation
Presentation is loading. Please wait.
Published byLindsay Douglas Modified over 9 years ago
1
1 CS387/CS587: Note04 Lab 3
2
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
3
3 TreeView Controls Navigation Tab Property Nodes (Collection) –Root Nodes –Child Nodes –Node Properties Text NagivateUrl (Can be set later)
4
4 Content Page Should be created after master page Check Select Master Page Adding controls inside ContentPlaceHolder
5
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
6
Navigating all pages of Lab 3 6
7
ASP.NET Folders Solution Explorer Right click Web site Add ASP.NET Folder App_Code App_Data... 7
8
8 Accessing Database
9
9 Database File UWPCS3870.accdb How to upload data file Right click Apps_Data folder Select Add An Existing Item
10
10 Accessing Database Data Controls –SqlDataSource –AccessDataSource –... Code class –Connection –Command –DataAdpater –AdapterBuilder
11
DataClass Code class in folder App_Code No code module All variables and procedures should be Shared Otherwise, need to create object 11
12
Variables Private Const ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0; ” & _ “Data Source=|DataDirectory|\UWPCS3870.accdb" Private Shared prodAdapter As System.Data.OleDb.OleDbDataAdapter Private Shared prodBuilder As System.Data.OleDb.OleDbCommandBuilder Private Shared prodCmd As New Data.OleDb.OleDbCommand Private Shared con As New Data.OleDb.OleDBConnection Public Shared tblProduct As New Data.DataTable The objects are available all the time. 12
13
Setup Command and Adapter ‘ Sets up the connection, command and adapter Public 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
14
Retrieve Data Records ‘ Gets the table records and the table schema Public 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
15
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
16
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 client 16
17
Page Shopping Textchanged event of Textbox txtID id = txtID.Text.Trim index = -1 For x = 0 To DataClass.tblProducts.Rows.Count - 1 If DataClass.tblProducts.Rows(x)(0) = id Then index = x Exit For End If Next If index <> -1 Then txtName.Text = DataClass.tblProducts.Rows(index)(1) 17
18
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 found Else ‘ Found End If 18
19
Page Shopping Property AutoPastBack of Textbox Must be True to fire Textchanged event 19
20
Page Shopping Textchanged event of Textbox txtQuanity 20
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.