CS 3870/CS 5870 Test 2 (50 points) Thursday 2 - 4
Accessing Database Code class DataSource Control Your choice on the test
Data Binding GridView DetailsView Textbox DropDownList . . .
DetailsView AllowPage For end user For developer
Accessing Individual Elements of DetailsView c.TheID = DetailsView1.Rows(0).Cells(1).Text c.TheName = DetailsView1.Rows(1).Cells(1).Text
DropDownList One field of all records DataTextField DataValueField: PK column
DetailsView and DropDownList Using DropDownList to select records of DetailsView
Protected Sub DropDownList1_SelectedIndexChanged (sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged DetailsView1.PageIndex = DropDownList1.SelectedIndex End Sub
PostBack Default True for Buttons Default False for many other controls
Session Variables
Global.asax Session("Prog7_Bag") = New SortedList
Accessing Session Variables Protected Sub Page_Load(. . .) Handles Me.Load Dim bag As SortedList = Session("Prog7_Bag") . . . End Sub
Web User Control A class Can have other controls Properties Methods Events
Using Web User Control <%@ Register Src="~/Prog7/ShoppingItem.ascx" TagPrefix="uc1" TagName="ShoppingItem" %>
Placing User Controls on Forms At design time At run time
Adding to Forms at Run Time Protected Sub Page_Load(. . .) Handles Me.Load ‘ Need to find the form to add the control Dim theForm As Control = Master.Master.FindControl("form1") . . . theForm.Controls.Add(c1) End Sub
Adding to Placeholder at Run Time Protected Sub Page_Load(. . .) Handles Me.Load c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) . . . PlaceHolder1.Controls.Add(c1) End Sub
Adding to Panels at Run Time Protected Sub Page_Load(. . .) Handles Me.Load c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) . . . Panel1.Controls.Add(c1) End Sub
Web User Control as a Class Protected Sub btnBag_Click(. . .) Handles btnBag.Click c1 = New Prog7_ShoppingItem End Sub
Web User Control NOT as a Class Protected Sub Page_Load(. . .) Handles Me.Load ‘ New does not work c1 = CType(LoadControl("../ShoppingItem.ascx"), Prog7_ShoppingItem) theForm.Controls.Add(c1) End Sub
Public Event Define event Raise event Handle event
Test 2 (50 points) Thursday 2 - 4