Latest web development tutorials

ASP.NET DataValueField property

ListControl control Reference Manual ListControl control Reference Manual

Definition and Usage

DataValueField attribute specifies the data source to bind to field control Value property of each item.


Examples

The following example uses an XML file to populate RadioButtonList data:

<%@ Import Namespace="System.Data" %>

<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

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="You selected: " & rb.SelectedItem.Text
end sub
</script>

<form runat="server">
<asp:RadioButtonList id="rb" AutoPostBack="True"
runat="server" onSelectedIndexChanged="displayMessage" />
<asp:label id="lbl1" runat="server" />
</form>

The demonstration >>

XML document instance using countries.xml


ListControl control Reference Manual ListControl control Reference Manual