Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 9th, 2006, 02:41 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Survey App Question

I've taken the survey and am using parts of it. Maining the takesurvey.aspx and admin sections.

I've modified the Takesurvey.aspx to have up to 6 radiobuttons. Which works fine. Now what I would like to do is if there is no Answer for a particular radio button. I would like to disable the button. I'm struggling for a couple of days trying "findControl". I have question that will be setup of varing amount of answers and want to disable the radiobuttons when there is no answer for that radio button.

  #2 (permalink)  
Old May 11th, 2006, 11:02 AM
Authorized User
 
Join Date: Feb 2006
Location: Corona, CA, USA.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Shawn Livermore Send a message via Yahoo to Shawn Livermore
Default

Do you mean that you would disable radio button for 'f' if there was only a,b,c,d, and e?

There are several ways to do this...

I guess the most common way would be to go into the currentsurvey.ascx user control codebehind, and 'handle' the DataList1_ItemDataBound even. From here, intercept what is being bound to the data list and disable the radio buttons accordingly...

Good luck!

Thanks,

Shawn Livermore
MCAD, MCSD, PMP
http://www.shawnlivermore.blogspot.com
  #3 (permalink)  
Old May 11th, 2006, 11:53 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yup - that's exactly what I am trying to do. I am New to Asp.net. This is my first project.

here is the section of code on the .aspx page that I am talking about



<asp:DataList ID="DataList1" runat="server" DataSourceID="odsSurveyQuestions" >
  <ItemTemplate>
    <%=GetQuestionNum()%>. <%#Server.HtmlEncode(Eval("Text").ToString())%>
      <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="A" id="OptionA">A.
            <%#Server.HtmlEncode(Eval("OptionA").ToString())%> <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="B" id="OptionB">B.
            <%#Server.HtmlEncode(Eval("OptionB").ToString())%> <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="C" id="OptionC">C.
            <%#Server.HtmlEncode(Eval("OptionC").ToString())%> <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="D" id="OptionD">D.
            <%#Server.HtmlEncode(Eval("OptionD").ToString())%> <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="E" id="OptionE">E.
            <%#Server.HtmlEncode(Eval("OptionE").ToString())%> <br />
       <input name="Q<%#Eval("ID")%>" type="radio" value="F" id="OptionF">F.
              <%#Server.HtmlEncode(Eval("OptionF").ToString())%> <br /> <br /><br />
  </ItemTemplate>
</asp:DataList>

This is the code behind that I thought would do the trick but it doesn't work. When I run in debug mode I always get "nothing" for the Findcontrol("OptionF")

 Protected Sub Datalist1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound

        Dim RadioF As HtmlInputRadioButton = e.Item.FindControl("OptionF")
        If Not RadioF Is Nothing Then
            Dim OptionF As HtmlInputRadioButton = CType(RadioF, HtmlInputRadioButton)
            If OptionF.Name = "" Or OptionF.Name Is DBNull.Value Then
                Dim RadioFd As HtmlInputRadioButton = CType(RadioF, HtmlInputRadioButton)
                RadioFd.Disabled = "Disabled"
            End If

        End If

    End Sub

  #4 (permalink)  
Old May 13th, 2006, 05:57 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

For FindControl to work, the controls you're trying to find need an ID and a runat="server" attribute. Otherwise, they're just plain old HTML controls and they won't be found....

ALternatively, you could use true ASP.NET controls lime the <asp:RadioButton /> control.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Bruch Nr. 1 g-moll Op. 26: Vorspiel (Allegro moderato) by Mendelssohn & Bruch (Track 4 from the album: Violinkonzerte - Hoelscher) What's This?
  #5 (permalink)  
Old May 25th, 2006, 12:49 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice -
I when ahead and got it to work using asp controls. However I now cannot save the data to the database. The "Names" for the radionbuttons in the datalist get some system generated name with the group name appended to the end. the request.form function in the SaveResponses() cannot find these fields on the forms

here's the snippet from the takesurvey.aspx


<asp:DataList ID="DataList1" runat="server" DataSourceID="odsSurveyQuestions" OnItemDataBound ="DataList1_ItemDataBound" >
  <ItemTemplate>
    <%=GetQuestionNum()%>. <%#Server.HtmlEncode(Eval("Text").ToString())%>
      <br />
       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionA" />
           <asp:label id="lblOptionA" Runat="server"><%#Server.HtmlEncode(Eval("OptionA" ).ToString())%></asp:label><br />

       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionB" />
            <asp:label id="lblOptionB" Runat="server"><%#Server.HtmlEncode(Eval("OptionB" ).ToString())%></asp:label><br />

       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionC" />
            <asp:label id="lblOptionC" Runat="server"><%#Server.HtmlEncode(Eval("OptionC" ).ToString())%></asp:label><br />

       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionD" />
            <asp:label id="lblOptionD" Runat="server"><%#Server.HtmlEncode(Eval("OptionD" ).ToString())%></asp:label><br />

       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionE" />
            <asp:label id="lblOptionE" Runat="server"><%#Server.HtmlEncode(Eval("OptionE" ).ToString())%></asp:label> <br />

       <asp:radiobutton groupname="Q<%#Eval("ID")%>" Runat="server" id="OptionF" />
            <asp:label id="lbloptionF" Runat="server" ><%#Server.HtmlEncode(Eval("OptionF").ToString())% ></asp:label><br />

      <br /><br />
  </ItemTemplate>
</asp:DataList>



  #6 (permalink)  
Old May 25th, 2006, 01:16 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, they get these weird names because the controls are in a "naming container"; the DataList in this case.

You can find controls using the FindControl method, like this:

Dim myRadio As RadioButton = CType(e.Item.FindControl("MyRadio"), RadioButton)

This code find the radio button called MyRadio inside the Item property of the e argument and casts it to a proper RadioButton control. How you use this code depends on where you use it. Inside, say, an ItemDataBound event you can use it as is, as that event has an e argument with an Item property.

If, for example, you need to loop through the entire DataList, you can loop through its Items collection, and then use something like myItem.FindControl instead.

Other chapters, including the WebShop make use of FindControl as well.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
  #7 (permalink)  
Old May 26th, 2006, 11:50 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am looking at the WebShop application. I see what you are talking about. I will give it a try next week and let you know. Thankyou for your help.

  #8 (permalink)  
Old May 26th, 2006, 03:14 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome and good luck,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i handle 3 question in a survey blueguy Classic ASP Basics 6 October 24th, 2004 06:41 PM
Survey Question! NeedASP Classic ASP Databases 0 April 9th, 2004 12:59 PM
A question on bookstore sample app and pointbase partho_choudhury JSP Basics 0 April 9th, 2004 02:10 AM
A question on bookstore sample app and pointbase partho_choudhury Pro JSP 0 April 9th, 2004 02:09 AM
A question on bookstore sample app and pointbase partho_choudhury Java Databases 0 April 9th, 2004 02:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.