Click here to Skip to main content
15,891,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hiiiiiii,


I have a radiobutton list in a datalist retrived from the database question and its answers

I retrive the answers in the radiobutton list i do not have any problem so far.

I set the property autopostback =true it works good for the first and second radio button items but there is a problem in the third item.

Below is my datalist and radio button

XML
<asp:DataList ID="datalist_iq" runat="server" DataKeyField="id" BorderColor="Red">
                                <ItemTemplate>

                                    <table border="1">
                                        <tr>
                                            <td>
                                                <asp:Label ID="label_question_head" runat="server" Style="word-wrap: break-word" Width="310px" Height="91px" Font-Bold="true" ForeColor="Maroon">
                                                                    <%#Eval("q_head") %>

                                                </asp:Label>


                                            </td>
                                        </tr>

                                        <tr>

                                            <td rowspan="2">
                                                <asp:RadioButtonList ID="RadioButton1" AutoPostBack="true"  OnSelectedIndexChanged="RadioButton1_SelectedIndexChanged"   DataTextField="a_head" DataValueField="result" runat="server" Visible="true"  >


                                                </asp:RadioButtonList>

                                            </td>
                                        </tr>
                                    </table>


                               </ItemTemplate>
                          </asp:DataList>



and this is the code behind
C#
protected void RadioButton1_SelectedIndexChanged(object sender, EventArgs e)
  {
      Label_result.Text = "good";
    

     


      foreach (DataListItem dli in datalist_iq.Items)
      {


          rblfilteritem = (RadioButtonList)dli.FindControl("RadioButton1");
          foreach (ListItem item in rblfilteritem.Items)
          {
              if (item.Selected)
                  item.Selected = true;
          }
          Label_result.Text = rblfilteritem.SelectedItem.Text;

      }
Posted
Updated 6-May-14 21:19pm
v2
Comments
asmaaelshabaka 6-May-14 18:52pm    
when i retrive answers i retrive 3 answers that mean three radiobutton items the first and the second item is autopostback but the third item doesnot
ZurdoDev 6-May-14 21:51pm    
What's the error?
Prasad Avunoori 6-May-14 23:02pm    
Specify the error.
asmaaelshabaka 6-May-14 23:42pm    
the erreor is the third answer does not respone the auto post back does not work for this item in radiobuttonlist item
Rahul VB 7-May-14 2:59am    
Hello,
If you are posting the code....then you are going to post the complete code. Where is "Label_result" control "rblfilteritem" control ? Half of the controls are missing... How do you connect to the database. Ok, now i will have to assume certain things.
By the when you click the 3rd button what result does it show?

1 solution

I checked your code, it is working fine if each listitem value is unique but not working if values are duplicate.

Check values of listitems i.e result value.
 
Share this answer
 
Comments
asmaaelshabaka 7-May-14 8:30am    
yes thanks
but what if i want to bind the radiobuttonlist with three values the id and head of answer and result number i can only bind 2 values the id and head of answer with datavaluefield and datatextfield
MNamrata 8-May-14 3:28am    
I wont get you.Plz explain.

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