Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Prog3 Try and Catch Testing 2 Catching Database Errors Protected Sub DetailsView1_ItemDeleted( sender As Object, e As DetailsViewDeletedEventArgs)

Similar presentations


Presentation on theme: "1. Prog3 Try and Catch Testing 2 Catching Database Errors Protected Sub DetailsView1_ItemDeleted( sender As Object, e As DetailsViewDeletedEventArgs)"— Presentation transcript:

1 1

2 Prog3 Try and Catch Testing 2

3 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! 3

4 Accessing Controls on Master Page From ASPX page –Design View: OK –Source View: OK –May need to type 4

5 Accessing Controls on Master Page From VB file? –Property Master Dim db As SqlDataSource = Prog4MasterPage.getDataSource() On Master Page –Make a public function or property to return the control Public Function getDataSource() As SqlDataSource Return SqlDataSource1 End Function 5

6 Accessing Controls on Master Page You can use a Shared public function or use a Shared variable ‘ Prog4MasterPage Public Shared myDataSource As SqlDataSource Protected Sub Page_Load(...) Handles Me.Load myDataSource = SqlDataSource1 End Sub ‘ Page Updating Dim db As SqlDataSource = Prog4MasterPage.myDataSource 6

7 Page Default When visiting the page the first time, the first page is displayed. On any following visits, the page displayed last time should be displayed. Must use Session variable Checking IsPostBack in Page_Load 7

8 Page Updating When visiting the page later from other pages, the record previously displayed should still be shown on the form. Must use Session variable Form Load ‘ when not post back DetailsView1.PageIndex = Session("Prog4_RecordIndex") DetailsView1.PageIndexChanged Session("Prog4_RecordIndex") = DetailsView1.PageIndex 8

9 Prog 4 The new inserted record will still be displayed on the form after saved back to the database, and clicking on Next, Previous, First, and Last will show the correct record based on ProductID. 9

10 Protected Sub DetailsView1_ItemInserted(...) Handles DetailsView1.ItemInserted If e.Exception Is Nothing Then ‘ Completed ‘ find the index of the new added record ‘ modify DetailsView1.PageIndex Else ‘ failed End If End Sub 10

11 Protected Sub DetailsView1_ItemInserted(...) Handles DetailsView1.ItemInserted... ‘ find the index of the new added record... End Sub Protected Sub DetailsView1_ItemInserting(...) Handles DetailsView1.ItemInserting ' save the new ID Session("Prog4_NewID") = e.Values(0) End Sub 11

12 Dim dv As System.Data.DataView = SqlDataSource1.Select(DataSourceSelectArguments.Empty) Dim index As Integer = 0 For index = 0 To dv.Count - 1 Dim id As String = dv(index)(0) If id = Session("Prog4_NewID") Then Exit For End If Next DetailsView1.PageIndex = index 12 If SqlDataSource1 is on the Page

13 Dim db As SqlDataSource = Prog4MasterPage.myDataSource Dim dv As System.Data.DataView = db.Select(DataSourceSelectArguments.Empty) Dim index As Integer = 0 For index = 0 To dv.Count - 1 Dim id As String = dv(index)(0) If id = Session("Prog4_NewID") Then Exit For End If Next DetailsView1.PageIndex = index 13 If SqlDataSource1 is on the Master Page

14 Dim db As SqlDataSourdim db as sqldatasourcece = Prog4MasterPage.myDataSource Dim dv As System.Data.DataView = CType( db.Select(DataSourceSelectArguments.Empty), System.Data.DataView) Dim index As Integer = 0 For index = 0 To dv.Count – 1 ‘ Must Trim to handle ID with less than 3 chars Dim id As String = dv(index)(0).Trim If id = Session("Prog4_NewID") Then Exit For End If Next DetailsView1.PageIndex = index 14

15 Prog 4 The new inserted record will still be displayed on the form after saved back to the database, and clicking on Next, Previous, First, and Last will show the correct record based on ProductID. Using SQLDataSource Controls 15

16 How to Do it Using SqlDataClass? The new inserted record will still be displayed on the form after saved back to the database, and clicking on Next, Previous, First, and Last will show the correct record based on ProductID. Using SQLDataClass procedure? –Load table (otherwise at the end) –Find the index –DisplayRow 16

17 Test 1 Thursday, Oct 8 Lab 206 2:00 – 4:00 50 points 17

18 Test 1 CSS Files Nested Master Pages Post Back Session Variables Accessing Database Formatting Checking Input and Catching Errors 18


Download ppt "1. Prog3 Try and Catch Testing 2 Catching Database Errors Protected Sub DetailsView1_ItemDeleted( sender As Object, e As DetailsViewDeletedEventArgs)"

Similar presentations


Ads by Google