简体   繁体   中英

can not find dynamic html select in code behind

i have a class named "row" that has 3 item {property,instance,degree}. now i want to show my items or rows to user and if he changed the third part of class i edit it. this is my code of generating rows dynamically, numberOfInstance is number of rows.

<div id="hidden" class="hiddendiv">
<% 
 string matn = "";
 for (int i = 0; i < numberOfInstance ; i++)
 {
     row r= new row();
     r = a[i];
     matn+= " <div class='CMSdiv'>";
     matn += "<input id='Text"+i+"' class='labelhid' type='text'"+"value = '"+r.Property+ "'/>";
     matn += "<input id='Text2" + i + "' class='labelhid' type='text'" + "value = '" + r.instance+ "'/>";

     matn += " <select id='Select" +i+ "'class='drophid' runat='server'>";
     matn += " <option value= '"+ "خیلی زیاد"+"'>خیلی زیاد" + " <option value= '"+"زیاد'"+">زیاد";
     matn += " <option value='"+"متوسط'"+">متوسط";
     matn += " <option value='" + "کم'" + ">کم";
     matn += "</select>";
     matn += "</div>";
     Response.Write(matn);
     matn = "";

 }   

 %>

 </div>

now if user clicked on select and choose one option, i get it's value and pour to r.degree in code behind. but whatever i did i couldn't find it in code behind and was null. these are my attempts:

 var val = Request["Select" + i];
      string  selection = Request.Form["Select" + i];
        hd = (HiddenField)Page.FindControl("Select" + i);
  hd = (HiddenField)Control.FindControl("Select" + i);

You can't generate server side controls by Response.Write (More info here ). So html elements that you are writing to output are client side controls not server side and cannot be found using the Page.FindControl method.

Consider using one of the server side controls like Repeater instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM