Reading data FROM a dynamicly added control

Discussion in 'ASP .Net Web Controls' started by Fraggle, Nov 12, 2003.

  1. Fraggle

    Fraggle Guest

    *Posted elsewhere before, sorry if you saw it before*

    I am using PlaceHolders in a Repeater to generate a multi choice
    survey. I need a way of testing to see what the placeholder has been
    turned into at runtime, and reading out the data.

    The admin can add questions to a survey, then add possible answers to
    each question. Certain functions are also set, for example multi
    answer (display with a checkboxlist) single answer (radiolist). Also
    toggle the presence of an "other" selection which produces a textbox
    to type into.

    The questions and answers are held in a SQL Server Database.

    The survey output page reads the questions from the database, and
    builds the survey using a repeater.

    when a "respondent" arrives to fill out the survey they click the
    answers they wish, fill in the boxes and press submit.

    My problem is how do i then read out the checked answers?

    This link may work, may not :)

    http://bagheera.ncl.ac.uk/dps/DesktopDefault.aspx?tabindex=17&tabid=97

    if you break it I would be interested to know what you did :)
    Brief instructions, click add question to add a new Q. You MUST put an
    Integer in the Question number field. it does not auto number and a
    null will break it.

    Once a new Q is added click edit (pencil icon) and add Answers. (you
    can arrange the order of A with the up and down arrow. Note how the
    selected A *remains* selected!)

    I am not sure what code will help make my query understandable!

    Here is the template column for the repeater

    <itemTemplate>
    <table border="0">
    <tr>
    <td> <asp:HyperLink id= "editLink" ImageUrl="~/images/edit.gif"
    NavigateUrl='<%# "~/DesktopModules/awsurvey/Question_Edit.aspx?ItemID="
    & DataBinder.Eval(Container.DataItem, "ItemID") & "&mid=" & ModuleId
    %>' Visible= "<%# IsEditable %>" runat= "server" />
    <span class="normal">Q<%#
    Container.dataitem("questionNo") %></span></td>
    <td><span class="normal" style="font-size:1.1em;"><%#
    Container.dataitem("question") %> </span></td>
    </tr>
    <tr>
    <td rowspan="2">&nbsp;</td>
    <td><span class="normal" style="font-size:0.7em; color:blue;"> <%#
    Container.dataitem("Instruction") %> </span></td>
    </tr>
    <tr>
    <td><asp:placeHolder id="ph1" runat="server"/>
    <br>
    <asp:panel id="otherPanel" runat=server visible="false">
    <asp:label runat="server" id="other" /> Other (please
    specify)<asp:textbox id="otherTb" runat="server"/>
    </asp:panel>
    </td>
    </tr>
    </table>
    </itemTemplate>

    Here is the OnDataBound sub "type" is either "radio" or "checkbox".
    "other" is boolean.

    sub QuestionListDataBound(Sender As Object, e As
    RepeaterItemEventArgs)


    If (e.Item.ItemType = ListItemType.Item) Or _
    (e.Item.ItemType = ListItemType.AlternatingItem) Then

    select Case DataBinder.Eval(e.Item.DataItem, "type")

    case "radio" :

    dim lab as new radiobuttonlist
    lab.datasource = Questions.GetAnswersbyQuestion(
    DataBinder.Eval(e.Item.DataItem, "itemID"))
    lab.datatextfield="Answer"
    lab.DataValueField="itemId"

    lab.databind
    CType(e.Item.FindControl("ph1"),
    PlaceHolder).controls.add(lab)

    case "checkbox" :

    dim lab as new checkboxlist
    lab.datasource = Questions.GetAnswersbyQuestion(
    DataBinder.Eval(e.Item.DataItem, "itemID"))
    lab.datatextfield="Answer"
    lab.DataValueField="itemId"
    lab.databind
    CType(e.Item.FindControl("ph1"),
    PlaceHolder).controls.add(lab)

    end select



    if DataBinder.Eval(e.Item.DataItem, "other")

    CType(e.Item.FindControl("otherPanel"), panel).visible=true

    end if

    end if
    end sub


    Here is my submitClick (you can fill it in for me :)

    sub submit_click(sender As Object, e As System.EventArgs)

    ' get list of stuff in repeater
    ' go through each in list
    ' read out checked item(or items)
    ' read out "other" string
    ' enter all into DB

    end sub

    I bind to the repeater at page load

    QuestionList.DataSource =Questions.GetQuestions(ModuleId)
    QuestionList.DataBind()


    Thing I really want answered :-
    How do I read out what boxes where checked when a user hits the
    button.

    Thanks for any ideas.

    Fragg
    Fraggle, Nov 12, 2003
    #1
    1. Advertising

  2. Fraggle

    Alvin Bruney Guest

    you would have to do a findcontrol on the page container and then examine
    the property. so it would help to give each radiobutton a unique name so you
    know which one it is when you call find control.

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Fraggle" <> wrote in message
    news:...
    > *Posted elsewhere before, sorry if you saw it before*
    >
    > I am using PlaceHolders in a Repeater to generate a multi choice
    > survey. I need a way of testing to see what the placeholder has been
    > turned into at runtime, and reading out the data.
    >
    > The admin can add questions to a survey, then add possible answers to
    > each question. Certain functions are also set, for example multi
    > answer (display with a checkboxlist) single answer (radiolist). Also
    > toggle the presence of an "other" selection which produces a textbox
    > to type into.
    >
    > The questions and answers are held in a SQL Server Database.
    >
    > The survey output page reads the questions from the database, and
    > builds the survey using a repeater.
    >
    > when a "respondent" arrives to fill out the survey they click the
    > answers they wish, fill in the boxes and press submit.
    >
    > My problem is how do i then read out the checked answers?
    >
    > This link may work, may not :)
    >
    > http://bagheera.ncl.ac.uk/dps/DesktopDefault.aspx?tabindex=17&tabid=97
    >
    > if you break it I would be interested to know what you did :)
    > Brief instructions, click add question to add a new Q. You MUST put an
    > Integer in the Question number field. it does not auto number and a
    > null will break it.
    >
    > Once a new Q is added click edit (pencil icon) and add Answers. (you
    > can arrange the order of A with the up and down arrow. Note how the
    > selected A *remains* selected!)
    >
    > I am not sure what code will help make my query understandable!
    >
    > Here is the template column for the repeater
    >
    > <itemTemplate>
    > <table border="0">
    > <tr>
    > <td> <asp:HyperLink id= "editLink" ImageUrl="~/images/edit.gif"
    > NavigateUrl='<%# "~/DesktopModules/awsurvey/Question_Edit.aspx?ItemID="
    > & DataBinder.Eval(Container.DataItem, "ItemID") & "&mid=" & ModuleId
    > %>' Visible= "<%# IsEditable %>" runat= "server" />
    > <span class="normal">Q<%#
    > Container.dataitem("questionNo") %></span></td>
    > <td><span class="normal" style="font-size:1.1em;"><%#
    > Container.dataitem("question") %> </span></td>
    > </tr>
    > <tr>
    > <td rowspan="2">&nbsp;</td>
    > <td><span class="normal" style="font-size:0.7em; color:blue;"> <%#
    > Container.dataitem("Instruction") %> </span></td>
    > </tr>
    > <tr>
    > <td><asp:placeHolder id="ph1" runat="server"/>
    > <br>
    > <asp:panel id="otherPanel" runat=server visible="false">
    > <asp:label runat="server" id="other" /> Other (please
    > specify)<asp:textbox id="otherTb" runat="server"/>
    > </asp:panel>
    > </td>
    > </tr>
    > </table>
    > </itemTemplate>
    >
    > Here is the OnDataBound sub "type" is either "radio" or "checkbox".
    > "other" is boolean.
    >
    > sub QuestionListDataBound(Sender As Object, e As
    > RepeaterItemEventArgs)
    >
    >
    > If (e.Item.ItemType = ListItemType.Item) Or _
    > (e.Item.ItemType = ListItemType.AlternatingItem) Then
    >
    > select Case DataBinder.Eval(e.Item.DataItem, "type")
    >
    > case "radio" :
    >
    > dim lab as new radiobuttonlist
    > lab.datasource = Questions.GetAnswersbyQuestion(
    > DataBinder.Eval(e.Item.DataItem, "itemID"))
    > lab.datatextfield="Answer"
    > lab.DataValueField="itemId"
    >
    > lab.databind
    > CType(e.Item.FindControl("ph1"),
    > PlaceHolder).controls.add(lab)
    >
    > case "checkbox" :
    >
    > dim lab as new checkboxlist
    > lab.datasource = Questions.GetAnswersbyQuestion(
    > DataBinder.Eval(e.Item.DataItem, "itemID"))
    > lab.datatextfield="Answer"
    > lab.DataValueField="itemId"
    > lab.databind
    > CType(e.Item.FindControl("ph1"),
    > PlaceHolder).controls.add(lab)
    >
    > end select
    >
    >
    >
    > if DataBinder.Eval(e.Item.DataItem, "other")
    >
    > CType(e.Item.FindControl("otherPanel"), panel).visible=true
    >
    > end if
    >
    > end if
    > end sub
    >
    >
    > Here is my submitClick (you can fill it in for me :)
    >
    > sub submit_click(sender As Object, e As System.EventArgs)
    >
    > ' get list of stuff in repeater
    > ' go through each in list
    > ' read out checked item(or items)
    > ' read out "other" string
    > ' enter all into DB
    >
    > end sub
    >
    > I bind to the repeater at page load
    >
    > QuestionList.DataSource =Questions.GetQuestions(ModuleId)
    > QuestionList.DataBind()
    >
    >
    > Thing I really want answered :-
    > How do I read out what boxes where checked when a user hits the
    > button.
    >
    > Thanks for any ideas.
    >
    > Fragg
    Alvin Bruney, Nov 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henke
    Replies:
    5
    Views:
    646
    Munsifali Rashid
    Dec 30, 2003
  2. Henke
    Replies:
    1
    Views:
    465
  3. Anders K. Jacobsen [DK]

    Viewstate and dynamicly added controls

    Anders K. Jacobsen [DK], Mar 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    409
    Karl Seguin
    Mar 22, 2005
  4. Mike Housey

    Persistance of Dynamicly added user controls.

    Mike Housey, Aug 5, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    116
    Ken Cox [Microsoft MVP]
    Aug 8, 2003
  5. Jim Craddock via .NET 247

    Dynamicly Added Range Validator Acting Goofy

    Jim Craddock via .NET 247, Sep 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    123
    Jim Craddock via .NET 247
    Sep 15, 2004
Loading...

Share This Page