Groups | Blog | Home
all groups > asp.net webcontrols > november 2004 >

asp.net webcontrols : How can I get CheckBox value?



Stephane
11/26/2004 8:53:02 AM
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[i] + "<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


David
11/27/2004 9:55:15 AM
[quoted text, click to view]

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

AddThis Social Bookmark Button