Using C# to iterate form fields with same name
Posted
by itsatrp
on Stack Overflow
See other posts from Stack Overflow
or by itsatrp
Published on 2010-04-05T21:01:02Z
Indexed on
2010/04/05
21:03 UTC
Read the original article
Hit count: 221
I have a section of a form that I need to handle differently from the rest of form results. In the section that needs special handling I need to iterate over 3 form fields that have the same name. They have to have the same name, I can't change it. The section of the form I am referring to looks something like this:
<td><input name="Color" size="20" value="" type="text"></td>
Using C# I try something like this:
I try to handle it like this:
int i;
for (i = 1; i <= Request.Form["Color"][i]; i++) { colorName.Text += Request.Form["Color"]; }
Which leads to the following exception: System.NullReferenceException: Object reference not set to an instance of an object.
How should I be handling form fields with the same name?
© Stack Overflow or respective owner