Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using asp.net and i want to retrieve the checked value of input type radio button which is in stringbuilder. How to get that value when a asp.net button click event fires

What I have tried:

string rb1 = string.Empty;
string rb2 = string.Empty;
string rb3 = string.Empty;
string rb4 = string.Empty;
Label LblChoiceA = new Label();
Label LblChoiceB = new Label();
Label LblChoiceC = new Label();
Label LblChoiceD = new Label();
string options = string.Empty;

StringBuilder htmltable = new StringBuilder();

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
    htmltable.AppendFormat("<table border='0'><tr><td colspan='4'>{0}) {1}</td></tr><tr><td class='col-12'><input type='radio' id='" + rb1 + "{0}' name='" + options + "{0}' value='A' /> A) <label for='" + rb1 + "{0}' id='" + LblChoiceA + "'>{2}</label></td></tr><tr><td class='col-12'><input type='radio' id='" + rb2 + "{0}' name='" + options + "{0}' value='B' /> B) <label for='" + rb2 + "{0}' id='" + LblChoiceB + "'>{3}</label></td></tr><tr><td class='col-12'><input type='radio' id='" + rb3 + "{0}' name='" + options + "{0}' value='C' /> C) <label for='" + rb3 + "{0}' id='" + LblChoiceC + "'>{4}</label></td></tr><tr><td class='col-12'><input type='radio' id='" + rb4 + "{0}' name='" + options + "{0}' value='D' /> D) <label for='" + rb4 + "{0}' id='" + LblChoiceD + "'>{5}</label></td></tr></table>", ds.Tables[0].Rows[i]["QuestionNumber"], ds.Tables[0].Rows[i]["Question"], ds.Tables[0].Rows[i]["ChoiceA"], ds.Tables[0].Rows[i]["ChoiceB"], ds.Tables[0].Rows[i]["ChoiceC"], ds.Tables[0].Rows[i]["ChoiceD"]);
}
Posted
Comments
Member 8583441 19-Dec-18 3:14am    
i have used request.form to get the value of the radio button returning null
F-ES Sitecore 19-Dec-18 4:56am    
If it's a form post then use Request.Form["x"] where x is the "name" attribute of the radio button, not the id.
Member 8583441 19-Dec-18 5:15am    
yes sir it is form method post and i have given id value to request.form
for (int i = 0; i < dt.Rows.Count; i++)
{
string strSelected = Request.Form["options" + i];
}
but returning null value
F-ES Sitecore 19-Dec-18 5:19am    
View the source of the page with the form, is there any element on the page with a name attribute of "options0"?
Member 8583441 19-Dec-18 6:13am    
thanks for the suggestion i have checked the view source come to know that setting the value and not returning it. for that i went with storing that in hiddenfield using jquery and finally i got the solution for this issue thanks a lot sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900