1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before...

Preview:

DESCRIPTION

3 TreeView Controls Navigation Tab Property Nodes (Collection) –Root Nodes –Child Nodes –Node Properties Text NagivateUrl (Can be set later)

Citation preview

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 page ContentPlaceHolder Leave ContentPlaceHolder empty Add controls before ContentPlaceHolder• Adding a label• Adding a TreeView

3

TreeView Controls

• Navigation Tab• Property Nodes (Collection)

– Root Nodes– Child Nodes– Node Properties Text NagivateUrl (Can be set later)

4

Content Page

• Should be created after master page• Check Select Master Page• Adding controls inside ContentPlaceHolder

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

Navigating all pages of Lab 3

6

ASP.NET Folders

• Solution Explorer• Right click Web site• Add ASP.NET Folder• App_Code• App_Data• . . .

7

8

Accessing Database

9

Database File

• UWPCS3870.accdb

• How to upload data file Right click Apps_Data folder Select Add An Existing Item

10

Accessing Database

• Data Controls– SqlDataSource– AccessDataSource– . . .

• Code class– Connection– Command– DataAdpater – AdapterBuilder

DataClass

• Code class in folder App_Code• No code module• All variables and procedures should be Shared• Otherwise, need to create object

11

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

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

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

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

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 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 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 Shopping

Property AutoPastBack of Textbox

Must be True to fire Textchanged event

19

Page ShoppingTextchanged event of Textbox txtQuanity

20

Recommended