CSCI 6962: Server-side Desig n and Programming ASP Server Controls
Outline Creating complex UI components from toolbox – Checkboxes – Radio buttons – Lists Extracting data from components using code Multiple-select elements and array iteration Dynamic list generation
Complex Form Elements Checkboxes – Text property gives label to display next to box Radio buttons Lists – SelectionMode can be Single or Multiple
Lists and List Items Edit Items interface to add/edit items in this list – Add items to list – Set Text to appear next to it – Set Value to be passed as parameter if selected
Radio Button Lists Create as RadioButtonList to group together Same Edit Items interface
ASP vs. HTML
Reading CheckBoxes Checkboxes have Checked property (True or False) – Use to add “Monitor” to peripheralLabel – Like string-based conditional output in JSF ( adds line)
Reading Radio Buttons/Lists Simplest way to find out which element selected:.Text property – Returns value associated with element (“” if none selected) – Single-select Lists handled same way
Reading Multiple-Select Lists List stores array of all options (not just those selected) Use loop to iterate through all items – Listname.Items.Count gives number of items (loop from 0 to Count – 1) – Listname.Items[i] refers to i th item in list – Listname.Items[i].Selected true if i th item selected – Listname.Items[i].Value gives value of i th item
Reading Multiple-Select Lists Number of items in SoftwareList Was i th item selected? Get value associated with i th item Keep count of selected items so know whether any selected
Dynamic List Generation Adding items to list using code (usually in Page_Load): listname.Items.Add(new ListItem(string)) Example: generating list of months using loop from 1 to 12
Dates in ASP Key: Date object – Date.Today used to get current time/date – Date.Today.property gets specific values (Year, Month, Day, Hour, …)