GridView - RadioButton for survey, idea needed

Discussion in 'ASP .Net' started by Patrik, Sep 6, 2006.

  1. Patrik

    Patrik Guest

    hello,

    based on a client login I call a GridView that presents the appropriate
    questionnaire for that person. I added three columns (template fields)
    to the gridview that are radiobuttons. The client has to choose one
    radiobutton per row (either YES, NO, or PERHAPS). Yes would have a
    value of 1, No 2, perhaps 3.

    1) I need to restrict the choice to one of the three radiobuttons ?
    2) Need to insert the client's choice for every row in my table.

    maybe someone could fix the general idea below or propose somethnig
    else

    For each row in Gridview1.rows
    If (radiobutton1 = true) then result = 1
    ElseIf (radiobutton1 = true) then result = 2
    ElseIf (radiobutton1 = true) then result = 3
    EndIf
    resultrow = result
    Next
    Then again, i would need as many resultrow variables as there are rows,
    then I would do one insert because in my final table one line is one
    client and all his answers

    Thanks you
     
    Patrik, Sep 6, 2006
    #1
    1. Advertising

  2. Salut Patrik,

    It might be easier to put all of the choices in one column and then grab the
    selected value from that. Here's a little sample in case it gives you an
    idea. BTW, this uses the editable XMLDataSource from http://www.chaliy.com/
    ..

    Let us know?

    Ken
    Microsoft MVP [ASP.NET]

    <%@ Page Language="VB" %>
    <%@ register assembly="Chaliy.Web.UI.UpdatableXmlDataSource"
    namespace="Chaliy.Web.UI" tagprefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Radio Buttons in Gridview</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:gridview id="GridView1" runat="server" allowpaging="True"
    allowsorting="True" autogeneratecolumns="False"
    autogeneratedeletebutton="True" autogenerateeditbutton="True"
    datasourceid="UpdatableXmlDataSource1">
    <columns>
    <asp:templatefield headertext="Choice"
    sortexpression="Choice">
    <edititemtemplate>
    <asp:radiobuttonlist id="RadioButtonList1"
    runat="server" selectedvalue='<%# Bind("Choice") %>'>
    <asp:listitem value="1">Yes</asp:listitem>
    <asp:listitem value="2">No</asp:listitem>
    <asp:listitem value="3">Perhaps</asp:listitem>
    </asp:radiobuttonlist>
    </edititemtemplate>
    <itemtemplate>
    <asp:radiobuttonlist id="RadioButtonList1"
    runat="server" selectedvalue='<%# Bind("Choice") %>'>
    <asp:listitem value="1">Yes</asp:listitem>
    <asp:listitem value="2">No</asp:listitem>
    <asp:listitem value="3">Perhaps</asp:listitem>
    </asp:radiobuttonlist>
    </itemtemplate>
    </asp:templatefield>
    <asp:boundfield datafield="StringValue"
    headertext="StringValue" sortexpression="StringValue" />
    <asp:boundfield datafield="CurrencyValue"
    headertext="CurrencyValue" sortexpression="CurrencyValue" />
    <asp:boundfield datafield="Boolean" headertext="Boolean"
    sortexpression="Boolean" />
    </columns>
    </asp:gridview>

    <asp:hyperlink id="AddNewHyperLink" runat="server"
    navigateurl="~/AddNew.aspx">Add new</asp:hyperlink>
    <cc1:updatablexmldatasource id="UpdatableXmlDataSource1"
    runat="server" datafile="~/App_Data/TestData.xml" filterxpath="/Item"
    rootxpath="Data">
    <data>
    </data>
    </cc1:updatablexmldatasource>

    </div>
    </form>
    </body>
    </html>

    <?xml version="1.0" encoding="utf-8"?>
    <Data>
    <Item Choice="3" StringValue="Item1" CurrencyValue="1.99" Boolean="True"
    />
    <Item Choice="2" StringValue="Item2" CurrencyValue="2.99" Boolean="True"
    />
    <Item Choice="2" StringValue="Item3" CurrencyValue="3.99" Boolean="True"
    />
    <Item Choice="3" StringValue="Item4" CurrencyValue="5.99" Boolean="True"
    />
    <Item Choice="3" StringValue="Item5" CurrencyValue="4.99" Boolean="True"
    />
    </Data>


    "Patrik" <> wrote in message
    news:...
    > hello,
    >
    > based on a client login I call a GridView that presents the appropriate
    > questionnaire for that person. I added three columns (template fields)
    > to the gridview that are radiobuttons. The client has to choose one
    > radiobutton per row (either YES, NO, or PERHAPS). Yes would have a
    > value of 1, No 2, perhaps 3.
    >
    > 1) I need to restrict the choice to one of the three radiobuttons ?
    > 2) Need to insert the client's choice for every row in my table.
    >
    > maybe someone could fix the general idea below or propose somethnig
    > else
    >
    > For each row in Gridview1.rows
    > If (radiobutton1 = true) then result = 1
    > ElseIf (radiobutton1 = true) then result = 2
    > ElseIf (radiobutton1 = true) then result = 3
    > EndIf
    > resultrow = result
    > Next
    > Then again, i would need as many resultrow variables as there are rows,
    > then I would do one insert because in my final table one line is one
    > client and all his answers
    >
    > Thanks you
    >
     
    Ken Cox [Microsoft MVP], Sep 7, 2006
    #2
    1. Advertising

  3. Patrik

    Patrik Guest

    Thank you for the suggestion,

    I have to admit this would be quite easier, but for the actual task I
    have 5 choices (rating scale) and up to 40 questions, this would be to
    costly in space and my clients are used to the layout on paper.

    So I really have to figure it out. I CANNOT believe how difficult this
    seems and that no one had a similar problem, I have been reading for
    two days everywhere.

    I'll try some more and then I'll surrender for your option I guess.


    Ken Cox [Microsoft MVP] a écrit :

    > Salut Patrik,
    >
    > It might be easier to put all of the choices in one column and then grab the
    > selected value from that. Here's a little sample in case it gives you an
    > idea. BTW, this uses the editable XMLDataSource from http://www.chaliy.com/
    > .
    >
    > Let us know?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    >
    > <%@ Page Language="VB" %>
    > <%@ register assembly="Chaliy.Web.UI.UpdatableXmlDataSource"
    > namespace="Chaliy.Web.UI" tagprefix="cc1" %>
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <script runat="server">
    > </script>
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Radio Buttons in Gridview</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:gridview id="GridView1" runat="server" allowpaging="True"
    > allowsorting="True" autogeneratecolumns="False"
    > autogeneratedeletebutton="True" autogenerateeditbutton="True"
    > datasourceid="UpdatableXmlDataSource1">
    > <columns>
    > <asp:templatefield headertext="Choice"
    > sortexpression="Choice">
    > <edititemtemplate>
    > <asp:radiobuttonlist id="RadioButtonList1"
    > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > <asp:listitem value="1">Yes</asp:listitem>
    > <asp:listitem value="2">No</asp:listitem>
    > <asp:listitem value="3">Perhaps</asp:listitem>
    > </asp:radiobuttonlist>
    > </edititemtemplate>
    > <itemtemplate>
    > <asp:radiobuttonlist id="RadioButtonList1"
    > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > <asp:listitem value="1">Yes</asp:listitem>
    > <asp:listitem value="2">No</asp:listitem>
    > <asp:listitem value="3">Perhaps</asp:listitem>
    > </asp:radiobuttonlist>
    > </itemtemplate>
    > </asp:templatefield>
    > <asp:boundfield datafield="StringValue"
    > headertext="StringValue" sortexpression="StringValue" />
    > <asp:boundfield datafield="CurrencyValue"
    > headertext="CurrencyValue" sortexpression="CurrencyValue" />
    > <asp:boundfield datafield="Boolean" headertext="Boolean"
    > sortexpression="Boolean" />
    > </columns>
    > </asp:gridview>
    >
    > <asp:hyperlink id="AddNewHyperLink" runat="server"
    > navigateurl="~/AddNew.aspx">Add new</asp:hyperlink>
    > <cc1:updatablexmldatasource id="UpdatableXmlDataSource1"
    > runat="server" datafile="~/App_Data/TestData.xml" filterxpath="/Item"
    > rootxpath="Data">
    > <data>
    > </data>
    > </cc1:updatablexmldatasource>
    >
    > </div>
    > </form>
    > </body>
    > </html>
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <Data>
    > <Item Choice="3" StringValue="Item1" CurrencyValue="1.99" Boolean="True"
    > />
    > <Item Choice="2" StringValue="Item2" CurrencyValue="2.99" Boolean="True"
    > />
    > <Item Choice="2" StringValue="Item3" CurrencyValue="3.99" Boolean="True"
    > />
    > <Item Choice="3" StringValue="Item4" CurrencyValue="5.99" Boolean="True"
    > />
    > <Item Choice="3" StringValue="Item5" CurrencyValue="4.99" Boolean="True"
    > />
    > </Data>
    >
    >
    > "Patrik" <> wrote in message
    > news:...
    > > hello,
    > >
    > > based on a client login I call a GridView that presents the appropriate
    > > questionnaire for that person. I added three columns (template fields)
    > > to the gridview that are radiobuttons. The client has to choose one
    > > radiobutton per row (either YES, NO, or PERHAPS). Yes would have a
    > > value of 1, No 2, perhaps 3.
    > >
    > > 1) I need to restrict the choice to one of the three radiobuttons ?
    > > 2) Need to insert the client's choice for every row in my table.
    > >
    > > maybe someone could fix the general idea below or propose somethnig
    > > else
    > >
    > > For each row in Gridview1.rows
    > > If (radiobutton1 = true) then result = 1
    > > ElseIf (radiobutton1 = true) then result = 2
    > > ElseIf (radiobutton1 = true) then result = 3
    > > EndIf
    > > resultrow = result
    > > Next
    > > Then again, i would need as many resultrow variables as there are rows,
    > > then I would do one insert because in my final table one line is one
    > > client and all his answers
    > >
    > > Thanks you
    > >
     
    Patrik, Sep 7, 2006
    #3
  4. Patrik

    Patrik Guest

    Here's how I am solving it :
    radiobuttonlist in the itemtemplate, i make it horizontal, then i add a
    table on top of the grid to insert the headertext for the buttons.


    Patrik a écrit :

    > Thank you for the suggestion,
    >
    > I have to admit this would be quite easier, but for the actual task I
    > have 5 choices (rating scale) and up to 40 questions, this would be to
    > costly in space and my clients are used to the layout on paper.
    >
    > So I really have to figure it out. I CANNOT believe how difficult this
    > seems and that no one had a similar problem, I have been reading for
    > two days everywhere.
    >
    > I'll try some more and then I'll surrender for your option I guess.
    >
    >
    > Ken Cox [Microsoft MVP] a écrit :
    >
    > > Salut Patrik,
    > >
    > > It might be easier to put all of the choices in one column and then grab the
    > > selected value from that. Here's a little sample in case it gives you an
    > > idea. BTW, this uses the editable XMLDataSource from http://www.chaliy.com/
    > > .
    > >
    > > Let us know?
    > >
    > > Ken
    > > Microsoft MVP [ASP.NET]
    > >
    > > <%@ Page Language="VB" %>
    > > <%@ register assembly="Chaliy.Web.UI.UpdatableXmlDataSource"
    > > namespace="Chaliy.Web.UI" tagprefix="cc1" %>
    > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > >
    > > <script runat="server">
    > > </script>
    > >
    > > <html xmlns="http://www.w3.org/1999/xhtml" >
    > > <head runat="server">
    > > <title>Radio Buttons in Gridview</title>
    > > </head>
    > > <body>
    > > <form id="form1" runat="server">
    > > <div>
    > > <asp:gridview id="GridView1" runat="server" allowpaging="True"
    > > allowsorting="True" autogeneratecolumns="False"
    > > autogeneratedeletebutton="True" autogenerateeditbutton="True"
    > > datasourceid="UpdatableXmlDataSource1">
    > > <columns>
    > > <asp:templatefield headertext="Choice"
    > > sortexpression="Choice">
    > > <edititemtemplate>
    > > <asp:radiobuttonlist id="RadioButtonList1"
    > > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > > <asp:listitem value="1">Yes</asp:listitem>
    > > <asp:listitem value="2">No</asp:listitem>
    > > <asp:listitem value="3">Perhaps</asp:listitem>
    > > </asp:radiobuttonlist>
    > > </edititemtemplate>
    > > <itemtemplate>
    > > <asp:radiobuttonlist id="RadioButtonList1"
    > > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > > <asp:listitem value="1">Yes</asp:listitem>
    > > <asp:listitem value="2">No</asp:listitem>
    > > <asp:listitem value="3">Perhaps</asp:listitem>
    > > </asp:radiobuttonlist>
    > > </itemtemplate>
    > > </asp:templatefield>
    > > <asp:boundfield datafield="StringValue"
    > > headertext="StringValue" sortexpression="StringValue" />
    > > <asp:boundfield datafield="CurrencyValue"
    > > headertext="CurrencyValue" sortexpression="CurrencyValue" />
    > > <asp:boundfield datafield="Boolean" headertext="Boolean"
    > > sortexpression="Boolean" />
    > > </columns>
    > > </asp:gridview>
    > >
    > > <asp:hyperlink id="AddNewHyperLink" runat="server"
    > > navigateurl="~/AddNew.aspx">Add new</asp:hyperlink>
    > > <cc1:updatablexmldatasource id="UpdatableXmlDataSource1"
    > > runat="server" datafile="~/App_Data/TestData.xml" filterxpath="/Item"
    > > rootxpath="Data">
    > > <data>
    > > </data>
    > > </cc1:updatablexmldatasource>
    > >
    > > </div>
    > > </form>
    > > </body>
    > > </html>
    > >
    > > <?xml version="1.0" encoding="utf-8"?>
    > > <Data>
    > > <Item Choice="3" StringValue="Item1" CurrencyValue="1.99" Boolean="True"
    > > />
    > > <Item Choice="2" StringValue="Item2" CurrencyValue="2.99" Boolean="True"
    > > />
    > > <Item Choice="2" StringValue="Item3" CurrencyValue="3.99" Boolean="True"
    > > />
    > > <Item Choice="3" StringValue="Item4" CurrencyValue="5.99" Boolean="True"
    > > />
    > > <Item Choice="3" StringValue="Item5" CurrencyValue="4.99" Boolean="True"
    > > />
    > > </Data>
    > >
    > >
    > > "Patrik" <> wrote in message
    > > news:...
    > > > hello,
    > > >
    > > > based on a client login I call a GridView that presents the appropriate
    > > > questionnaire for that person. I added three columns (template fields)
    > > > to the gridview that are radiobuttons. The client has to choose one
    > > > radiobutton per row (either YES, NO, or PERHAPS). Yes would have a
    > > > value of 1, No 2, perhaps 3.
    > > >
    > > > 1) I need to restrict the choice to one of the three radiobuttons ?
    > > > 2) Need to insert the client's choice for every row in my table.
    > > >
    > > > maybe someone could fix the general idea below or propose somethnig
    > > > else
    > > >
    > > > For each row in Gridview1.rows
    > > > If (radiobutton1 = true) then result = 1
    > > > ElseIf (radiobutton1 = true) then result = 2
    > > > ElseIf (radiobutton1 = true) then result = 3
    > > > EndIf
    > > > resultrow = result
    > > > Next
    > > > Then again, i would need as many resultrow variables as there are rows,
    > > > then I would do one insert because in my final table one line is one
    > > > client and all his answers
    > > >
    > > > Thanks you
    > > >
     
    Patrik, Sep 7, 2006
    #4
  5. Sounds good!

    "Patrik" <> wrote in message
    news:...
    Here's how I am solving it :
    radiobuttonlist in the itemtemplate, i make it horizontal, then i add a
    table on top of the grid to insert the headertext for the buttons.


    Patrik a écrit :

    > Thank you for the suggestion,
    >
    > I have to admit this would be quite easier, but for the actual task I
    > have 5 choices (rating scale) and up to 40 questions, this would be to
    > costly in space and my clients are used to the layout on paper.
    >
    > So I really have to figure it out. I CANNOT believe how difficult this
    > seems and that no one had a similar problem, I have been reading for
    > two days everywhere.
    >
    > I'll try some more and then I'll surrender for your option I guess.
    >
    >
    > Ken Cox [Microsoft MVP] a écrit :
    >
    > > Salut Patrik,
    > >
    > > It might be easier to put all of the choices in one column and then grab
    > > the
    > > selected value from that. Here's a little sample in case it gives you an
    > > idea. BTW, this uses the editable XMLDataSource from
    > > http://www.chaliy.com/
    > > .
    > >
    > > Let us know?
    > >
    > > Ken
    > > Microsoft MVP [ASP.NET]
    > >
    > > <%@ Page Language="VB" %>
    > > <%@ register assembly="Chaliy.Web.UI.UpdatableXmlDataSource"
    > > namespace="Chaliy.Web.UI" tagprefix="cc1" %>
    > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > >
    > > <script runat="server">
    > > </script>
    > >
    > > <html xmlns="http://www.w3.org/1999/xhtml" >
    > > <head runat="server">
    > > <title>Radio Buttons in Gridview</title>
    > > </head>
    > > <body>
    > > <form id="form1" runat="server">
    > > <div>
    > > <asp:gridview id="GridView1" runat="server" allowpaging="True"
    > > allowsorting="True" autogeneratecolumns="False"
    > > autogeneratedeletebutton="True" autogenerateeditbutton="True"
    > > datasourceid="UpdatableXmlDataSource1">
    > > <columns>
    > > <asp:templatefield headertext="Choice"
    > > sortexpression="Choice">
    > > <edititemtemplate>
    > > <asp:radiobuttonlist id="RadioButtonList1"
    > > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > > <asp:listitem value="1">Yes</asp:listitem>
    > > <asp:listitem value="2">No</asp:listitem>
    > > <asp:listitem
    > > value="3">Perhaps</asp:listitem>
    > > </asp:radiobuttonlist>
    > > </edititemtemplate>
    > > <itemtemplate>
    > > <asp:radiobuttonlist id="RadioButtonList1"
    > > runat="server" selectedvalue='<%# Bind("Choice") %>'>
    > > <asp:listitem value="1">Yes</asp:listitem>
    > > <asp:listitem value="2">No</asp:listitem>
    > > <asp:listitem
    > > value="3">Perhaps</asp:listitem>
    > > </asp:radiobuttonlist>
    > > </itemtemplate>
    > > </asp:templatefield>
    > > <asp:boundfield datafield="StringValue"
    > > headertext="StringValue" sortexpression="StringValue" />
    > > <asp:boundfield datafield="CurrencyValue"
    > > headertext="CurrencyValue" sortexpression="CurrencyValue" />
    > > <asp:boundfield datafield="Boolean" headertext="Boolean"
    > > sortexpression="Boolean" />
    > > </columns>
    > > </asp:gridview>
    > >
    > > <asp:hyperlink id="AddNewHyperLink" runat="server"
    > > navigateurl="~/AddNew.aspx">Add new</asp:hyperlink>
    > > <cc1:updatablexmldatasource id="UpdatableXmlDataSource1"
    > > runat="server" datafile="~/App_Data/TestData.xml" filterxpath="/Item"
    > > rootxpath="Data">
    > > <data>
    > > </data>
    > > </cc1:updatablexmldatasource>
    > >
    > > </div>
    > > </form>
    > > </body>
    > > </html>
    > >
    > > <?xml version="1.0" encoding="utf-8"?>
    > > <Data>
    > > <Item Choice="3" StringValue="Item1" CurrencyValue="1.99"
    > > Boolean="True"
    > > />
    > > <Item Choice="2" StringValue="Item2" CurrencyValue="2.99"
    > > Boolean="True"
    > > />
    > > <Item Choice="2" StringValue="Item3" CurrencyValue="3.99"
    > > Boolean="True"
    > > />
    > > <Item Choice="3" StringValue="Item4" CurrencyValue="5.99"
    > > Boolean="True"
    > > />
    > > <Item Choice="3" StringValue="Item5" CurrencyValue="4.99"
    > > Boolean="True"
    > > />
    > > </Data>
    > >
    > >
    > > "Patrik" <> wrote in message
    > > news:...
    > > > hello,
    > > >
    > > > based on a client login I call a GridView that presents the
    > > > appropriate
    > > > questionnaire for that person. I added three columns (template fields)
    > > > to the gridview that are radiobuttons. The client has to choose one
    > > > radiobutton per row (either YES, NO, or PERHAPS). Yes would have a
    > > > value of 1, No 2, perhaps 3.
    > > >
    > > > 1) I need to restrict the choice to one of the three radiobuttons ?
    > > > 2) Need to insert the client's choice for every row in my table.
    > > >
    > > > maybe someone could fix the general idea below or propose somethnig
    > > > else
    > > >
    > > > For each row in Gridview1.rows
    > > > If (radiobutton1 = true) then result = 1
    > > > ElseIf (radiobutton1 = true) then result = 2
    > > > ElseIf (radiobutton1 = true) then result = 3
    > > > EndIf
    > > > resultrow = result
    > > > Next
    > > > Then again, i would need as many resultrow variables as there are
    > > > rows,
    > > > then I would do one insert because in my final table one line is one
    > > > client and all his answers
    > > >
    > > > Thanks you
    > > >
     
    Ken Cox [Microsoft MVP], Sep 7, 2006
    #5
    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. Merichel

    RadioButton in a GridView

    Merichel, Aug 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    13,243
    SerhaD
    Aug 2, 2006
  2. Replies:
    10
    Views:
    1,269
    Big K
    Feb 2, 2005
  3. Dr Mephesto

    App idea, Any idea on implementation?

    Dr Mephesto, Feb 4, 2008, in forum: Python
    Replies:
    3
    Views:
    745
    Dennis Lee Bieber
    Feb 5, 2008
  4. Replies:
    0
    Views:
    653
  5. sofie
    Replies:
    3
    Views:
    264
    holland amsterdam
    Dec 1, 2003
Loading...

Share This Page