parameters with radio button values...

Posted on 2007-08-01
Last Modified: 2013-11-26
I have a stored proceedure that is for a questionaire that when finished will be written to sql.  My problem is that I am not sure what coding needs to be used for the paramerter for radio button values. All my validation is currently done on the client side using javascript.
This is what I have now:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace RUOK
      /// <summary>
      /// Summary description for survey.
      /// </summary>
      public class survey : System.Web.UI.Page
            protected System.Web.UI.WebControls.RadioButton radioQ1_2;
            protected System.Web.UI.WebControls.RadioButton radioQ1_1;
            protected System.Web.UI.WebControls.Label lblQ1Tip1;
            protected System.Web.UI.WebControls.RadioButton radioQ2_2;
            protected System.Web.UI.WebControls.RadioButton radioQ2_1;
            protected System.Web.UI.WebControls.RadioButton radioQ2_0;
            protected System.Web.UI.WebControls.Label lblQ2Tip;
            protected System.Web.UI.WebControls.RadioButton radioQ3_2;
            protected System.Web.UI.WebControls.RadioButton radioQ3_1;
            protected System.Web.UI.WebControls.RadioButton radioQ3_0;
            protected System.Web.UI.WebControls.Label lblQ3Tip;
            protected System.Web.UI.WebControls.RadioButton radioQ4_2;
            protected System.Web.UI.WebControls.RadioButton radioQ4_1;
            protected System.Web.UI.WebControls.RadioButton radioQ4_0;
            protected System.Web.UI.WebControls.RadioButton radioQ5_2;
            protected System.Web.UI.WebControls.RadioButton radioQ5_1;
            protected System.Web.UI.WebControls.RadioButton radioQ5_0;
            protected System.Web.UI.WebControls.RadioButton radioQ6_2;
            protected System.Web.UI.WebControls.RadioButton radioQ6_1;
            protected System.Web.UI.WebControls.RadioButton radioQ6_0;
            protected System.Web.UI.WebControls.RadioButton radioQ7_2;
            protected System.Web.UI.WebControls.RadioButton radioQ7_1;
            protected System.Web.UI.WebControls.RadioButton radioQ7_0;
            protected System.Web.UI.WebControls.RadioButton radioQ8_1;
            protected System.Web.UI.WebControls.RadioButton radioQ8_0;
            protected System.Web.UI.WebControls.RadioButton radioQ10_1;
            protected System.Web.UI.WebControls.RadioButton radioQ13_2;
            protected System.Web.UI.WebControls.RadioButton radioQ8_2;
            protected System.Web.UI.WebControls.RadioButton radioQ9_2;
            protected System.Web.UI.WebControls.RadioButton radioQ9_1;
            protected System.Web.UI.WebControls.RadioButton radioQ9_0;
            protected System.Web.UI.WebControls.RadioButton radioQ10_2;
            protected System.Web.UI.WebControls.RadioButton radioQ10_0;
            protected System.Web.UI.WebControls.RadioButton radioQ11_2;
            protected System.Web.UI.WebControls.RadioButton radioQ11_1;
            protected System.Web.UI.WebControls.RadioButton radioQ11_0;
            protected System.Web.UI.WebControls.RadioButton radioQ12_2;
            protected System.Web.UI.WebControls.RadioButton radioQ12_1;
            protected System.Web.UI.WebControls.RadioButton radioQ12_0;
            protected System.Web.UI.WebControls.RadioButton radioQ13_1;
            protected System.Web.UI.WebControls.RadioButton radioQ15_1;
            protected System.Web.UI.WebControls.RadioButton radioQ17_2;
            protected System.Web.UI.WebControls.RadioButton radioQ1_0;
            protected System.Web.UI.WebControls.RadioButton radioQ13_0;
            protected System.Web.UI.WebControls.RadioButton radioQ14_2;
            protected System.Web.UI.WebControls.RadioButton radioQ14_1;
            protected System.Web.UI.WebControls.RadioButton radioQ14_0;
            protected System.Web.UI.WebControls.RadioButton radioQ15_2;
            protected System.Web.UI.WebControls.RadioButton radioQ15_0;
            protected System.Web.UI.WebControls.RadioButton radioQ16_2;
            protected System.Web.UI.WebControls.RadioButton radioQ16_1;
            protected System.Web.UI.WebControls.RadioButton radioQ16_0;
            protected System.Web.UI.WebControls.RadioButton radioQ17_1;
            protected System.Web.UI.WebControls.RadioButton radioQ17_0;
            protected System.Web.UI.WebControls.RadioButton radioQ18_2;
            protected System.Web.UI.WebControls.RadioButton radioQ18_1;
            protected System.Web.UI.WebControls.RadioButton radioQ18_0;
            protected System.Web.UI.WebControls.RadioButton RadioGenderF;
            protected System.Web.UI.WebControls.RadioButton radioResidentY;
            protected System.Web.UI.WebControls.RadioButton radioResidentN;
            protected System.Web.UI.WebControls.RadioButton RadioGender;
            protected System.Web.UI.WebControls.RadioButton RadioGenderM;
            protected System.Web.UI.WebControls.DropDownList ddAgeRange;
            protected System.Web.UI.WebControls.TextBox hiddenTotalScore;
            protected System.Web.UI.WebControls.Label lblDateTime;

            private const string stpRUOKInsertNew = "stp_RUOK_InsertNew";
            private void Page_Load(object sender, System.EventArgs e)
                  if (IsPostBack)
                        DataSet ds = new DataSet();
                          SqlParameter [] prm = new SqlParameter[21];
                              prm[0] = new SqlParameter("@agerange",this.ddAgeRange.SelectedValue + RemoveDefaultValues(this.ddAgeRange.SelectedValue));
                              prm[1] = new SqlParameter ("@gender", this.RadioGender.Checked);
                        ds = SqlHelper.ExecuteDataset((ConfigurationSettings.AppSettings["SQLConnectionString"]), CommandType.StoredProcedure, stpRUOKInsertNew,prm);
                  catch(Exception ex)
                        throw ex;

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
                  this.Load += new System.EventHandler(this.Page_Load);



Question by:mockweb
    LVL 96

    Expert Comment

    by:Bob Learned
    What kind of validation are you talking about?  What is your question really?


    Author Comment

    i am validating the questionaire that has 18 questions and 3 possible answers using radio buttons. My question is when I try to use my stored proceedure I am not sure what property is used..
    and example would be a text box with an id of txtlname would use .Text what would you use for a radio button .Checked?
     prm[0] = new SqlParameter("@lname",this.txtlname.Text);
    LVL 96

    Expert Comment

    by:Bob Learned
    Yes, with the RadioButton, you would use the Checked property.  What kind of parameter are you accessing with the RadioButton Checked value?


    Author Comment

    i only want to insert information so i am accessing the input parameter. I am very new at this so excuse me if i am using the wrong terminology.
    LVL 96

    Expert Comment

    by:Bob Learned
    Ok, but what data are you trying to insert into the database that is associated with the RadioButton control?


    Author Comment

    OK let me give you the whole thing.

    I have 18 questions
    each answer is a radio button with a group name (Question1), Question 2 etc
    each radio button will have a value of 2, 1, or 0.

    depending on what the user selects 2, 1, or 0. That is the information that I need to insert.  So say the user selects 2 as the answer I want that value  (2)written to the database.
    LVL 96

    Accepted Solution

    1) I would use a RadioButtonList instead of separate RadioButton controls.

    2) Then, you could use the RadioButtonList.SelectedIndex property to get the currently selected index, and write that value to the database with an Integer parameter.

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Viewers will learn how the fundamental information of how to create a table.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now