How can I get CheckBox value?

S

Stephane

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
 
D

David

Stephane said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top