ASP.NET Web Forms - Data Binding
We can use data binding to create lists with selectable options, where these options come from an imported data source, such as a database, XML file, or script.
Data Binding
The following controls are list controls that support data binding:
- asp:RadioButtonList
- asp:CheckBoxList
- asp:DropDownList
- asp:Listbox
The options for each of the above controls are typically defined in one or more asp:ListItem controls, as follows:
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="countrylist" runat="server">
<asp:ListItem value="N" text="Norway" />
<asp:ListItem value="S" text="Sweden" />
<asp:ListItem value="F" text="France" />
<asp:ListItem value="I" text="Italy" />
</asp:RadioButtonList>
</form>
</body>
</html>
<body>
<form runat="server">
<asp:RadioButtonList id="countrylist" runat="server">
<asp:ListItem value="N" text="Norway" />
<asp:ListItem value="S" text="Sweden" />
<asp:ListItem value="F" text="France" />
<asp:ListItem value="I" text="Italy" />
</asp:RadioButtonList>
</form>
</body>
</html>
However, we can use an independent data source, such as a database, XML file, or script, for data binding to populate the list options.
By using an imported data source, data is separated from HTML, and modifications to the options are all made in the independent data source.
In the following three chapters, we will describe how to bind data from scripted data sources.
Other Extensions