RadioButtonList Binding options Dynamically
In general we declare the options of a RadioButtonList control statically in the .aspx page, but what if we need to set these values at runtime based on data from a database, we shall see on how to achieve this.
The Asp.Net RadioButtonList control allows data binding similar to a GridView or Dropdown List control, using which we can bind a data source to the RadioButtonList control.
In the .aspx page just add the RadioButtonList tag without adding any options as follows.
Select Name:
<asp:RadioButtonList
ID="radListName"
runat="server"
RepeatDirection="Vertical">
</asp:RadioButtonList>
Then navigate to the code behind file and add the required options as follows.
protected void Page_Load(object sender, EventArgs e)
{
radListName.DataSource = dtEmployee;
radListName.DataValueField = "ID";
radListName.DataTextField = "Name";
radListName.DataBind();
}
That’s it we have bound the options to the RadioButtonList control at runtime.
No comments:
Post a Comment