1 / 12

CIS 375—Web App Dev II

CIS 375—Web App Dev II. ASP .NET 7 Binding (based on w3schools.com— also see MSDN .NET development. Data Binding 1. The following are list controls that support data binding: asp:RadioButtonList [ Example ] asp:CheckBoxList [ Example ] asp:DropDownList [ Example ]

maddox
Télécharger la présentation

CIS 375—Web App Dev II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 375—Web App Dev II ASP .NET 7 Binding (based on w3schools.com— also see MSDN .NET development

  2. Data Binding 1 • The following are list controls that support data binding: • asp:RadioButtonList [Example] • asp:CheckBoxList [Example] • asp:DropDownList [Example] • asp:Listbox [Example]

  3. Data Binding 2 • However, with data binding we may use a separate source, like a database, an _____ file, or a script to fill the list with selectable items. • By using an imported source, the data is separated from the ______, and any changes to the items are made in the separate data source.

  4. ArrayList 1 • The ArrayList object is a collection of items containing a _______ data value. • Items are added to the ArrayList with the Add() method. <script runat="server"> Sub Page_Load if Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("Norway") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") end if end sub </script>

  5. ArrayList 2 • By default, an ArrayList object contains ___ entries. • An ArrayList can be sized to its final size with the TrimToSize() method: mycountries.TrimToSize() • An ArrayList can also be sorted alphabetically or numerically with the Sort() method: mycountries.Sort() • To sort in reverse order, apply the Reverse() method after the Sort() method: mycountries.Reverse()

  6. ArrayList 3 • An ArrayList object may automatically generate the text and _______ to the following controls: • asp:RadioButtonList • asp:CheckBoxList • asp:DropDownList • asp:Listbox • To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page: <form runat="server"> <asp:RadioButtonList id="rb" runat="server" /> </form>

  7. ArrayList 4 (Example) • Then add the script that builds the list and binds the values in the list to the RadioButtonList control: <script runat="server"> Sub Page_Load if Not Page.IsPostBack then dim mycountries=New ArrayList mycountries.Add("Norway") mycountries.Add("Sweden") mycountries.Add("France") mycountries.Add("Italy") mycountries.TrimToSize() mycountries.Sort() rb.DataSource=mycountries rb.DataBind() end if end sub </script>

  8. Hashtable 1 • The Hashtable object contains items in ____/value pairs. • The keys are used as indexes, and very quick searches can be made for values by searching through their keys. • Items are added to the Hashtable with the Add() method. dim mycountries=New Hashtable mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy")

  9. Hashtable 2 (Example) • A Hashtable object may automatically generate the text and values to the following controls: • asp:RadioButtonList • asp:CheckBoxList • asp:DropDownList • asp:Listbox • Then add this script to the Hashtable: rb.DataSource=mycountries rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() • Then we add a subroutine to be executed when the user clicks on an item in the RadioButtonList control.

  10. SortedList (Example) • The SortedList object contains items in key/value pairs. • A SortedList is a hybrid between a Hashtable and an Array using the Hashtable key or Array ________. • A SortedList object automatically sorts the items in alphabetic or numeric order. dim mycountries=New SortedList mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") • The code for SortedList is the same as for Hashtable.

  11. XML Files 1 • You can bind an XML file to a list control. • Take a look at the XML file: countries.xml • Bind a DataSet to a List Control • First, import the "System.Data" namespace. • We need this namespace to work with DataSet objects. • Include the following directive at the top of an .aspx page: • <%@ Import Namespace="System.Data" %>

  12. XML Files 2 (Example) • Take a look at the XML file: countries.xml • Create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded: <script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycountries=New DataSet mycountries.ReadXml(MapPath("countries.xml")) rb.DataSource=mycountries rb.DataValueField="value" rb.DataTextField="text" rb.DataBind() end if end sub </script>

More Related