c# - ASP Dropdown list with options set to false -


i have dropdownlist of form:

 <asp:dropdownlist runat="server" cssclass="holdtypeddl" id="holdtypeddl"></asp:dropdownlist> 

and filled onload in c# codebehind of aspx page when !page.ispostback via :

 holdtypeddl.items.add(new listitem(string.empty, false.tostring()));             holdtypeddl.items.add(new listitem(holdtypetype.now.description(), false.tostring()));             holdtypeddl.items.add(new listitem(holdtypetype.aaholdtype.description(), true.tostring()));             holdtypeddl.items.add(new listitem(holdtypetype.aaaholdtype.description(), true.tostring()));             holdtypeddl.items.add(new listitem(holdtypetype.aaaaholdtype.description(), false.tostring())); 

i have noticed if 1 of options of select selected have string value of false, not consider selected. i.e. selected index 0 after postback. if item true selected , value grabbed on postback, works fine.

i cannot find documentation why is. why having "false" string in value of option element make not post properly?

edit:

renders in html such:

<select class="holdtypeddl" id="bodycontent_holdtypeddl" name="ctl00$bodycontent$holdtypeddl">     <option value="false"></option>     <option value="false">now</option>     <option value="true">aa hold type</option>     <option value="true">aaa hold type</option>     <option value="false">aaaa hold type</option>  </select> 

i believe values should unique. because have multiple true, false values, when marks selected, takes first 1 value selected. why using these values? use same text, or change values this:

holdtypeddl.items.add(new listitem(string.empty, false.tostring() + "0")); holdtypeddl.items.add(new listitem(holdtypetype.now.description(), false.tostring() + "1")); holdtypeddl.items.add(new listitem(holdtypetype.aaholdtype.description(), true.tostring() + "2")); holdtypeddl.items.add(new listitem(holdtypetype.aaaholdtype.description(), true.tostring() + "3")); holdtypeddl.items.add(new listitem(holdtypetype.aaaaholdtype.description(), false.tostring() + "4")); 

that should work.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -