Each control has a primary way to bind data to it, and they generally fall into two categories, namely, directly bound and templated. A directly-bound control uses individual fields, such as the .Text
and .Value
properties, or individual controls such as the <asp:BoundField>
and <asp:ImageField>
controls. A couple of simple examples of this type of control, besides the GridView control, are the <asp:DropDownList>
and <asp:CheckBoxList>
.
The <asp
:DropDownList>
exposes the properties DataSource
, DataTextField
, and DataValueField
. By setting these properties, either in the aspx page or the code behind, our data will be bound to the control. The aspx code for this control would be something like as follows:
<asp:DropDownList ID="productDropDownList" DataTextField="ProductName" DataValueField="Image" runat="server" />
When we view the page with a browser, the control that gets generated is as follows:
The <asp:CheckBoxList>...