Slide 13.11: Web server controls (cont.)
Slide 14.2: The ArrayList object
Home

Data Binding


We may use data binding to fill lists with selectable items from an imported data source, like a database, an XML file, or a script. The following controls are list controls which support data binding: The selectable items in each of the above controls are usually defined by one or more ListItem controls, like this:


demo_radiobuttonlist.aspx

Web
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="VB" runat="server">
 Sub submit( sender As Object, e As EventArgs )
  label1.Text = "You selected " & radiolist1.SelectedItem.Text
 End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" > 
 <body> 
  <form runat="server">
   <asp:RadioButtonList id="radiolist1" runat="server">
    <asp:ListItem selected="true">Item 1</asp:ListItem>
    <asp:ListItem>Item 2</asp:ListItem>
    <asp:ListItem>Item 3</asp:ListItem>
    <asp:ListItem>Item 4</asp:ListItem>
   </asp:RadioButtonList>
   <asp:Button text="Submit" OnClick="submit" runat="server" />
   <p><asp:Label id="Label1" runat="server" /></p>
  </form>
 </body>
</html>

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