locked
Comment désactiver un élément de DropDownList RRS feed

  • Discussion générale

  • <asp:DropDownList ID="DropDownList1" runat ="server" Width="235px" AutoPostBack="False">
        <asp:ListItem>1</asp:ListItem>
        <asp:ListItem>2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
    </asp:DropDownList>
    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList1.Attributes.Add("onchange", "change();");
    }<script type ="text/javascript" >
          function change()
          {
             var dd=document.getElementById ('<%=DropDownList1.ClientID %>');
             var value=dd.options[dd.selectedIndex].value;
             if(value!="2") //supose you want to disable the item numbered 2
             {
                setTimeout("__doPostBack('DropDownList1','')", 0);
             }
           }
    </script>

     

     

    Pour plusieurs informations sur ASP.NET, consultez  Foire aux Questions - ASP.NET

     

     


    Alex Petrescu - MSFT
    mardi 30 mars 2010 11:30
    Modérateur