views:

1025

answers:

1

I am receiving long string of checked html checkbox values (Request.Form["mylist"] return Value1,Value2,Value3....) on the form post in ASP.NET 2.0 page.

Now I simply want to loop these but I don't know what is the best practice to loop this array of string. I am trying to do something like this:

foreach (string Item in Request.Form["mylist"]){
  Response.Write(Request.Form["mylist"][Item] + "<hr>");
}

But it does not work.

+6  A: 

You have to split the comma separated string. Try

string myList = Request.Form["myList"];
if(string.isNullOrEmpty(myList))
{
    Response.Write("Nothing selected.");
    return;
}
foreach (string Item in myList.split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries))
{
  Response.Write(item + "<hr>");
}
SolutionYogi