20
1 CS387/CS587: Note04 Lab 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

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: 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

1

CS387/CS587: Note04

Lab 3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Page ShoppingTextchanged event of Textbox txtQuanity

20