Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

RadioButtonList problem...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bodyboarder20 - 25 Sep 2007 15:43 GMT
I'm currently using a GridView and during the RowDataBound event, I am
populated a radio list within the row.  The problem is, when I click a
button on the bottom of the page, I am able to grab the
RadioButtonList from the GridView; however, it is not retaining the
users selection.  It either retains -1 (no selection), or whatever I
set it to during the RowDataBound event.

Does anybody know how to get around this?

Thanks!!

Code:
------------------------------------------------------
<asp:GridView ID="GridView1" OnRowDataBound="GridView1_RowDataBound"
runat="server" AutoGenerateColumns="false" AllowPaging="true"
DataSourceID="AccessDataSource1" DataKeyNames="ID" Width="100%"
PageSize="1" BorderStyle="None" BorderWidth="0px">
                       <Columns>
                           <asp:TemplateField>
                               <HeaderTemplate></HeaderTemplate>
                               <ItemTemplate>
                                   <table width="100%">
                                       <tr>
                                           <td><h3>Question <%#
GridView1.PageIndex+1 %>: <%# Eval("Question") %></h3></td>
                                       </tr>
                                       <tr>
                                           <td>
                                               <asp:RadioButtonList
ID="RBLAnswerList" runat="server" >
                                               </asp:RadioButtonList>
                                           </td>
                                       </tr>

                                   </table>
                               </ItemTemplate>
                               <FooterTemplate></FooterTemplate>
                           </asp:TemplateField>
                       </Columns>
                       <PagerSettings Visible="False" />
                   </asp:GridView>

------------------------------------------------------

   protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
   {
       // Set session variables for this question
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           Session.Add("CurrentQuestionID",
(int)DataBinder.Eval(e.Row.DataItem, "ID"));
           Session.Add("CurrentQuestionCorrectAnswer",
(int)DataBinder.Eval(e.Row.DataItem, "CorrectAnswer"));

           ArrayList answers =
FormatAnswers(DataBinder.Eval(e.Row.DataItem, "answers"));

           RadioButtonList radio =
(RadioButtonList)e.Row.FindControl("RBLAnswerList");

           radio.DataSource = answers;
           radio.DataBind();
       }
   }

   protected void NextButton_Click(object sender, EventArgs e)
   {

       RadioButtonList rbl =
(RadioButtonList)GridView1.Rows[0].FindControl("RBLAnswerList");

       Answer ans = new Answer((int)Session["CurrentQuestionID"],

(int)Session["CurrentQuestionCorrectAnswer"],
                               rbl.SelectedIndex);

       ArrayList al = (ArrayList)Session["QuizAnswerList"];
       al.Add(ans);

       Session.Add("QuizAnswerList", al);

       if (GridView1.PageIndex == GridView1.PageCount - 1)
       {
           Response.Redirect("Results.aspx");
       }
       else
       {
           GridView1.PageIndex++;
       }

       if (GridView1.PageIndex == GridView1.PageCount - 1)
               NextButton.Text = "Finished";
   }
------------------------------------------------------
Bodyboarder20 - 25 Sep 2007 17:43 GMT
I found my problem!

I was databinding to the GridView at the bottom my PageLoad.  This was
getting called before my Button click event... hence overwriting the
users selection back to default.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.