• User

    [ASP.NET] DropDownList (Selected Value)

    Ciau a tutti....
    sono dinuovo qui per chiedervi aiuto ...vi espongo il mio problema.....
    In una pagina web in aspx visualizzo dei dati presi da un db , questi dati li visualizzo in base al mese di riferimento e permetto di sceglierlo....con una
    DropDownList ...vi posto il codice presente nell'aspx:
    <asp:DropDownList EnableViewState=True id="DropDownList1" runat="server" style=" MARGIN-LEFT:65px;margin-top:50px;">
    <asp:ListItem Value="1">Gennaio</asp:ListItem>
    <asp:ListItem Value="2">Febbraio</asp:ListItem>
    <asp:ListItem Value="3">Marzo</asp:ListItem>
    <asp:ListItem Value="4">Aprile </asp:ListItem>
    <asp:ListItem Value="5" Maggio</asp:ListItem>
    <asp:ListItem Value="6" Selected="True">>Giugno</asp:ListItem>
    <asp:ListItem Value="7">Luglio</asp:ListItem>
    <asp:ListItem Value="8">Agosto</asp:ListItem>
    <asp:ListItem Value="9">Settembre</asp:ListItem>
    <asp:ListItem Value="10">Ottobre</asp:ListItem>
    <asp:ListItem Value="11">Novembre</asp:ListItem>
    <asp:ListItem Value="12">Dicembre</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server">
    <asp:ListItem Value="2004">2004</asp:ListItem>
    <asp:ListItem Value="2005">2005</asp:ListItem>
    <asp:ListItem Value="2006">2006</asp:ListItem>
    <asp:ListItem Value="2007" Selected="True">2007</asp:ListItem>
    <asp:ListItem Value="2008">2008</asp:ListItem>
    <asp:ListItem Value="2009">2009</asp:ListItem>
    <asp:ListItem Value="2010">2010</asp:ListItem>
    <asp:ListItem Value="2011">2011</asp:ListItem>
    <asp:ListItem Value="2012">2012</asp:ListItem>
    </asp:DropDownList>

    dove seleziono a true il mese e l'anno che voglio che venga visualizzato per primo....
    il mio problema è il seguente.....:
    voglio fare la stessa cosa da .cs ossia non mettere Selected="True" nell'aspx ma farlo da cs come posso fare....non ho trovato da nessuna parte l'istruzione esatta con la seguente :
    DropDownList1.SelectedItem.Value
    selezione un mese già settato....ma io voglio settarlo in cs come posso fare qual'è l'istruzione esatta ....😢aiuto😢


  • User Attivo

    DropDownList1.selectedValue=tuovalore


  • User

    ho provato a inserire l'istruzione nel pageLoad ma mi da errore.....:😢
    Method not found: Void System.Web.UI.WebControls.ListControl.set_SelectedValue(System.String).
    **Description: **An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    **Exception Details: **System.MissingMethodException: Method not found: Void System.Web.UI.WebControls.ListControl.set_SelectedValue(System.String).

    **Source Error:**An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:

    [MissingMethodException: Method not found: Void System.Web.UI.WebControls.ListControl.set_SelectedValue(System.String).] xenia.tabella_spons.Page_Load(Object sender, EventArgs e) +0 System.Web.UI.Control.OnLoad(EventArgs e) System.Web.UI.Control.LoadRecursive() System.Web.UI.Page.ProcessRequestMain() Cos'ho dimenticato...devo ancora mettere qualcosa????io ho scrittoDropDownList2.SelectedValue="2007";
    😢


  • User Attivo

    Impossibile, deve funzionare per forza. Forse hai usato nomi diversi.

    Se la dropdown si chiama id="drop1" allora nel pageload devi mettere drop1.selectedvalue=tuovalore. Dove, ovviamente, "tuovalore" è un numero che corrisponde al mese (1 o 2 o 3...etc. etc.)