How can I get CheckBox value?

Discussion in 'ASP .Net Web Controls' started by Stephane, Nov 26, 2004.

  1. Stephane

    Stephane Guest

    Hi,

    I have created dynamically some check box using CheckBoxList. I' trying to
    retreive those check boxes values with Request.From but I only get "on" for
    checked boxes.

    I did the same for radio button using RadioButtonList and droplist and it
    works great.

    How can I retrieve those values??

    Here's how I fill my lists:

    ListControl bList;
    if (question.AnswerTypeId == SurveyQuestion.RADIO)
    bList = new RadioButtonList();
    else
    bList = new CheckBoxList();
    foreach (SurveyAnswer answer in question.AnswersList.Values)
    {
    ListItem item = new ListItem(" " + answer.Answer, ANSWER_VALUE +
    answer.AnswerId.ToString());
    bList.Items.Add(item);
    }

    And this is how I try to retrieve them:

    if (this.IsPostBack)
    {
    for (int i=0; i<Request.Form.Count; i++)
    {
    Response.Write(Request.Form + "<br>");
    }

    It prints:

    answer_12 // Radio
    answer_14 // Radio
    on // Checkbox
    on // Checkbox
    answer_56 // Droplist

    I need to get the value instead of the "on".

    Any idea?

    Thanks

    Stephane
    Stephane, Nov 26, 2004
    #1
    1. Advertising

  2. Stephane

    David Guest

    Stephane wrote:
    > Hi,
    >
    > I have created dynamically some check box using CheckBoxList. I'
    > trying to retreive those check boxes values with Request.From but I
    > only get "on" for checked boxes.
    >
    > I did the same for radio button using RadioButtonList and droplist
    > and it works great.
    >
    > How can I retrieve those values??
    >
    > Here's how I fill my lists:
    >
    > ListControl bList;
    > if (question.AnswerTypeId == SurveyQuestion.RADIO)
    > bList = new RadioButtonList();
    > else
    > bList = new CheckBoxList();
    > foreach (SurveyAnswer answer in question.AnswersList.Values)
    > {
    > ListItem item = new ListItem(" " + answer.Answer, ANSWER_VALUE +
    > answer.AnswerId.ToString());
    > bList.Items.Add(item);
    > }
    >
    > And this is how I try to retrieve them:
    >
    > if (this.IsPostBack)
    > {
    > for (int i=0; i<Request.Form.Count; i++)
    > {
    > Response.Write(Request.Form + "<br>");
    > }
    >
    > It prints:
    >
    > answer_12 // Radio
    > answer_14 // Radio
    > on // Checkbox
    > on // Checkbox
    > answer_56 // Droplist
    >
    > I need to get the value instead of the "on".
    >
    > Any idea?
    >
    > Thanks
    >
    > Stephane


    If you have a reason to work with Form,
    Request.Form.GetKey(i) will help you.
    You'll still have some decoding to do.

    However, the best way to do this is in ASP.NET is to
    rebuild your listcontrol on postback, and to iterate the
    bList.Items collection, which will give you all the values
    you want.

    --

    David
    David, Nov 27, 2004
    #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. Edmilson

    Checkbox - How can i get the value ?

    Edmilson, Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    444
    Edmilson
    Jun 27, 2003
  2. Shufen
    Replies:
    4
    Views:
    836
    Shufen
    Oct 3, 2004
  3. Imran Aziz

    checkbox value attribute in checkbox control ?

    Imran Aziz, Aug 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    221
    Imran Aziz
    Aug 8, 2005
  4. Jack

    How can I get the checkbox's value

    Jack, Oct 14, 2003, in forum: ASP General
    Replies:
    1
    Views:
    98
  5. randy
    Replies:
    13
    Views:
    433
    Tad McClellan
    Nov 1, 2003
Loading...

Share This Page