c# - Dropdownlist problem -


i don't understand why can't ddl selected value..

asp code:

<table>     <tr>       <th> annee:</th>          <td>             <asp:dropdownlist id="ddlannee" runat="server" />          </td>     </tr>     <tr>       <th colspan="2">          <asp:button id="btnvalidate" runat="server" onclick="btnvalidate_click"                                      text="validate"  />        </th>     </tr> </table> 

code behind:

protected void page_load(object sender, eventargs e)         {             if (!ispostback)             {                 bindcontrols();             }         }          public void bindcontrols()         {             this.ddlannee.datasource = new bll.annee_manager().list(false, true, null);             this.ddlannee.datatextfield = "intitule_an";             this.ddlannee.datavaluefield = "id_an";             this.ddlannee.databind();         }          protected void btnvalidate_click(object sender, eventargs e)         {             int id_an = int.parse( this.ddlannee.selectedvalue);          }     } } 

so, when put break point @ page load , binding part, it's ok, ddl filled correctly , page show correctly ddl. when click on button, arrive in btnvalidate_click method ddl empy!

i suppose i've forgot something.. please me!

thanks..

do not remove ispostback, bindcontrol method should in !ispostback condition otherwise never going selected value. make sure of method not clearing ddlannee dropdown.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -