Click here to Skip to main content
15,797,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi experts.

i have a problem for binding radio buttons in gridview. i am doing a project online test. bing each question have 4/5 radio buttons. here i write the sample code

<asp:DataList ID="dalsurvey" runat="server">
                                      <span style="font-size:14px; font-weight:bold;"<%#Eval("Answers")%></span>
                                          <input name="MyRadioButton" class="radioButton" type="radio" id='<%# Eval("Description") %>' value='<%# Eval("Description") %>'  <%# Convert.ToString(Eval("Description")) != "" ? "" : "hidden"  %>  />
                                           <asp:Label ID="Label2" runat="server" Text='<%#Eval("Description") %>'></asp:Label>

here i should be able to select only one. but i want to select in each question one radio button.. how can i do this...?

1 solution

to add Redio button inside grid view you have to add templatefield
as given below :

<asp:GridView ID="GridView1" runat="server">
<asp:BoundField DataField="PID" HeaderText="PID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="PName" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:TemplateField HeaderText="Select One">
<input name="RadioButton" type="radio" value='<%# Eval("value") %>' />
</ asp:GridView >
Share this answer
NaniCh 26-Mar-13 8:12am    
Thanks for u r giving answer. here we can able to select only one radio button. but i have multiple quetions with multiple answers. we should be select one radio button in each question.. how to bind it..?
[no name] 26-Mar-13 8:21am    
if you want to select one question and multiple answer then you have to bind checkbok for the answers and redio buttons for questions
NaniCh 26-Mar-13 8:28am    
no i have multiple questions with multiple answers.. each question have put only one answer how can i bind.?

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