nvs_victor
asked on
Getting a SELECT MULTIPLE element to pass its multiple values into an array, after a POST.
Hi experts,
I’m having trouble getting a SELECT MULTIPLE element to pass its multiple values into an array, after a POST.
Basically it’s this question:
http://www.sitepoint.com/f orums/show thread.php ?163734-Pr ocess-a-SE LECT-MULTI PLE-POST
But how do I pass it into an array in ASP.NET C# syntax? Is it possible?
Currently, I have this code:
When I run the file, I get this error.
Apparently, the POST operation is passing the country element as a string. I need it to pass as an array, as the link talks about in PHP.
I assume I can’t do this with ASP.NET C#, am I correct? Do I need PHP to do this?
Thanks!
I’m having trouble getting a SELECT MULTIPLE element to pass its multiple values into an array, after a POST.
Basically it’s this question:
http://www.sitepoint.com/f
But how do I pass it into an array in ASP.NET C# syntax? Is it possible?
Currently, I have this code:
@{
String [] countryID ;
if (IsPost) {
countryID = Request.Form["country[]"];
}
}
<select multiple size="10" name="country[]" style="width: 200px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</option>
</select>
When I run the file, I get this error.
CS0029: Cannot implicitly convert type 'string' to 'string[]'
Apparently, the POST operation is passing the country element as a string. I need it to pass as an array, as the link talks about in PHP.
I assume I can’t do this with ASP.NET C#, am I correct? Do I need PHP to do this?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I can't even reproduce what I saw yesterday with the zero thing... bizarre!
ASKER
robert_schutt helped me assure me that it will pass comma separated.
ASKER
Thanks for your prompt help!
Strangely, today, it's working as expecting... producing a comma separated value.
Yesterday, without the array [] thing, it was only displaying the correct value if only one item was selected, but when multiple items were selected, it would display 0. Hence why I asked this question.
Strange. I don't recall anything I did differently from yesterday.
But it is good news :)
Thanks for your help!