0

I have such form, and i want to get values of each id in foreach loop

Price      <input type="text" id="1" name="items" value="" /> <br />
Condition  <input type="text" id="2" name="items" value="" /> <br />
Brand      <input type="text" id="3" name="items" value="" /> <br />

       string[] items = Request.Form.GetValues("items");

       foreach(var ax in items){

           Response.Write("<br/>" + ax +  "-" +Request['id']);
       }

Is such thing possible in asp.net ?

ktm
  • 6,025
  • 24
  • 69
  • 95

1 Answers1

2

You need to have unique names for each input. You can then loop through the Request.Form collection and get their values like this...

<form action="" method="post">
Price      <input type="text" id="1" name="items_1" value="" /> <br /> 
Condition  <input type="text" id="2" name="items_2" value="" /> <br /> 
Brand      <input type="text" id="3" name="items_3" value="" /> <br /> 
<input type="submit">
</form>

@{
       foreach(string ax in Request.Form){ 
           if (ax.StartsWith("items_")) {
               string id = ax.Substring(6);
               Response.Write("<br/>" + id +  "-" +Request.Form[ax]); 
           }
       } 
}
johna
  • 10,540
  • 14
  • 47
  • 72