In this article we will cover different ways to Bind or Populate RadioButtonList Control in Asp.Net
<asp:RadioButtonList ID="ddlGender" runat="server"></asp:RadioButtonList>
Example 1
List<Gender> genders = new List<Gender>() { new Gender(){ Name = "Male",Value = "M"}, new Gender(){ Name = "Female",Value = "F"} }; ddlGender.DataSource = genders; ddlGender.DataTextField = "Name"; ddlGender.DataValueField = "Value"; ddlGender.DataBind();
Example 2
ddlGender.Items.Add(new ListItem() { Text = "Male", Value = "M" }); ddlGender.Items.Add(new ListItem() { Text = "Female", Value = "F" });
Example 3
// (Use this method when items needs to be added on perticular index) ddlGender.Items.Insert(1, new ListItem() { Text = "Male", Value = "M" }); ddlGender.Items.Insert(2, new ListItem() { Text = "Female", Value = "F" });
Post Comments(0)