CS143: Programming in C++
Download
Report
Transcript CS143: Programming in C++
CS 3870/CS 5870: Note07
Prog 4
1
Master Pages
• Creating a master page based on another
master page
• MainMasterPage
– For all Progs and Tests
• Prog4MasterPage
– For Prog 4 only
2
Main Master Page
• Head
– Title: UWP – CS 3870/CS 5870
– ContentPlaceHolder with ID “head”
– Link to CSS file
• Body
–
–
–
–
–
Form
Div
H1: Web Protocols . . .
H2: Names
ContentPlaceHolder with “ContentPlaceHolder1”
3
Prog4MasterPage
• No head or body or form
– All are in MainMasterPage
• Content for “head”
– What can be added here?
– CSS file link
• Content for “ContentPlaceHolder1”
– All controls should be within this Content
– TreeView (not completed)
– Add a new ContentPlaceHolder using ToolBox
4
Content Pages
• Add New Items
–
–
–
–
Web Form
Select Master Page
Place code in separate file
Default.aspx
• Add Web Form (with master)
– Updating.aspx
– Shopping.aspx
5
Content Pages
• Content for ContentPlaceHolder1
– All controls should be within this content
control
• Cannot access ContentPlaceHolders in
MainMasterPage directly
6
Prog4MasterPage
• Complete TreeView on Prog4MasterPage
– Source view
– Design view
7
TreeView Controls
•
•
Navigation Tab
Property Nodes (Collection)
–
–
–
Root Nodes
Child Nodes
Node Properties
Text
NagivateUrl
8
Accessing Database
•
Data Source Controls
–
–
–
•
Code class
–
–
–
–
•
•
SqlDataSource
AccessDataSource
...
Connection
Command
DataAdpater
AdapterBuilder
Prog 3: Use Code class
Prog 4: Use Data Source Controls
9
SqlDataSource
• Data Tab on ToolBox
• Smart Tag
– Configure Data Source
• New Connection
– Server Name: Xray\Sqlexpress
– User SQL Server Authentication
– User name: jim
– Password: UWPCS3870 (case sensitive)
– Select or enter a database name: UWPCS3870 (case sensitive)
– OK
• Next
10
SqlDataSource
• Yes, save this connection as
• Specify columns from a table or view
– Product
– Where
– Order By…
– Advanced
• Generate Insert, Update and Delete statements: Check
• Use optimistic concurrency: Check
• Test Query
• Finish
11
Data Bound Controls
•
•
•
•
•
•
•
Data Tag
GridView
FormView
DetailsView
DataList
ListView
...
12
Page Default
• Must use GridView
• Choose Data Source
• Must Format Fields
13
Format GridView
• AutoFormat
– Your choice
• Edit Columns
• Select fields
– Data Field
– Header Text
– ItemStyle
• Edit Templates
14
TemplateField
•
•
•
•
•
Edit Columns
UnitPrice
Convert this field into a TemplateField
OK
Edit Templates
– Select [Label]
– Smart Tag
– Edit Databindings
– May need to Refresh Schema
– Bound to: UnitPrice
– Format: Currency – {0;C}
• Smart Tag
• End Template Editing
15
GridView
•
•
•
•
•
Enable Paging: Yes
Enable Sorting: Yes
Enable Editing: No
Enable Deleting: No
Enable Selecting: No
16
Paging GridView
• Property Window
• Page size: 5
• Page Settings
– Mode: NextPreviousFirstLast
– Text: Next, Previous, First, Last
17
Page Updating
•
•
•
•
•
•
•
•
Any Data Bound Control
One record at a time
Navigate to all records
Sorted by ProductID
Update
Delete
New
Message textbox
18
Paging DetailsView
• Property Window
• Page Settings
– Mode: NextPreviousFirstLast
– Text: Next, Previous, First, Last
19
Auto Format DetailsView
20
Catching Database Errors
Protected Sub DetailsView1_ItemDeleted(
sender As Object,
e As DetailsViewDeletedEventArgs)
Handles DetailsView1.ItemDeleted
If Not e.Exception Is Nothing Then
e.ExceptionHandled = True
txtMessage.Text = e.Exception.Message
End If
End Sub
Not DetailsView1.ItemDeleting!
21
Page Shopping
• Page must be the same as Prog3
– Textboxes for the fields
– TextChange events
• SqlDataSource
• Binding textboxes to SqlDataSource?
22
Query with Parameters
• SqlDataSource
• Where
–
–
–
–
Column: ProductID
Operator: =
Source: None
Add
[ProductID] = @ProductID
• Test Query
23
Execute Query
‘ Get the ID
id = txtID.Text.Trim
‘ Set query parameter
SqlDataSource1.SelectParameters("ProductID").DefaultVa
lue = id
‘ Get the query result, which is a DataView
Dim dv As System.Data.DataView =
CType(SqlDataSource1.Select(
DataSourceSelectArguments.Empty),
System.Data.DataView)
24
Execute Query
‘ Get the ID
‘ Set query parameter
‘ Get the query result, which is a DataView
If dv.Count = 1 Then
‘ Valid ID
price = dv.Item(0)(2)
. . .
Else
‘ Invalid ID
End If
25
Prog 4
Bonus Points
Use one SqlDataSource for all pages.
26
Test 1
Thursday, October 9
27