Hi
I have below Radio Button . I want option P to be checked by default
Code
P
AThanks
Hi
I have below Radio Button . I want option P to be checked by default
P
AThanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Sep 19, 2022, 1:14 AM EDT
Hello
You can use RadioButtonList to achieve functionality using the radio button. please check the sample code below you can use.
You can set Selected="True" to set checked by default.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Sep 19, 2022, 1:17 AM EDT
Try the following fiddle I have created for you:
https://jsfiddle.net/0nbdycjx/1/
Sachin SinghRank #66 · 26.2K reputationPosted Sep 19, 2022, 1:38 AM EDT
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { rb1.Checked = true; } }I can't find anything wrong in your code. It should have worked. But, if for some reason it is not working then try setting it from code behind for the first load
Ramco RamcoRank #462 · 5.4K reputationPosted Sep 19, 2022, 1:51 AM EDT
Hi Muhammad
I am trying below code but not working
Thanks
Ramco RamcoRank #462 · 5.4K reputationPosted Sep 19, 2022, 1:52 AM EDT
Hi Sachin
RadioButton is in repeater
Thanks
Vishal JoshiRank #377 · 6.7K reputationPosted Sep 19, 2022, 1:59 AM EDT
Hello Ramco
It's an issue with your style sheet setting, not any issue with checked. it is check as you write Checked="true" just it's not showing to UI
You can try with the below code to review.
protected void button_Click(object sender, EventArgs e) { if (rb1.Checked) lblCheckBoxStatus.Text = "Option Selected: " + rb1.Text; else lblCheckBoxStatus.Text = "Option Selected: " + rb2.Text; }Ramco RamcoRank #462 · 5.4K reputationPosted Sep 19, 2022, 2:17 AM EDT
Hi Vishal
I have below code but still not showing Highlighted
Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Sep 19, 2022, 1:09 AM EDT
Try this
RadioButtonList1.SelectedIndex = 1; RadioButtonList1.SelectedValue = "P"; RadioButtonList1.Items[1].Selected = true;Ramco RamcoRank #462 · 5.4K reputationPosted Sep 19, 2022, 1:11 AM EDT
Hi Vishal
It is not a list.
Thanks