Hi,
Is it possible to bind to radio buttons instead of using a bunch of if statements??
Like
if (somestring == "01")
someradio.checked = true;
The thing is I have 25 radio buttons so i will need 25 if staements
Is it possible to bind to radio buttons instead of using a bunch of if statements??
Like
if (somestring == "01")
someradio.checked = true;
The thing is I have 25 radio buttons so i will need 25 if staements

Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jul 15, 2008, 9:19 AM EDT
aspx page code code-behind code. protected System.Web.UI.WebControls.Button btnTest; protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1; private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { //GetDataSet method returns a dataset from database. DataSet ds = GetDataSet("SELECT PRI_KEY, TEXT_DESC, SELECTED FROM TBLRADIO"); RadioButtonList1.DataTextField="text_desc"; RadioButtonList1.DataValueField="pri_key"; RadioButtonList1.DataSource=ds.Tables[0]; RadioButtonList1.DataBind(); DataRow[] dr = ds.Tables[0].Select("SELECTED=1"); RadioButtonList1.Items.FindByValue(dr[0][0].ToString()).Selected=true; } } private void btnTest_Click(object sender, System.EventArgs e) { Response.Write(RadioButtonList1.SelectedValue); }