Visualizzazione dei risultati da 1 a 4 su 4

Discussione: problemi con le select

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    7

    problemi con le select

    Ciao a tutti
    io ho questo codice che mi crea una select

    <code>
    Dim objDReader As OleDbDataReader
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & Server.MapPath("db\manuali.mdb")
    Dim objConn As New OleDbConnection(strConn)
    objConn.Open()
    Dim strQuery As string = "select * from argomenti order by argomento ASC"
    Dim objCom As new OleDbCommand(strQuery,objConn)
    objDReader=objCom.executeReader()
    argomento.DataSource=objDReader
    argomento.DataValueField="id_arg"
    argomento.DataTextField="argomento"
    argomento.DataBind()
    objConn.Close()
    </code>

    La select è definitivamente creata con gli argomenti recuperati.
    <code>
    <select id="argomento" runat="server" />
    </code>

    Adesso l'utente sceglie l'argomento e quando preme l'invio viene eseguito il codice seguente.

    <code>
    public Sub uploadManuali(strFile As String,strPercorsoFileUpload As string)

    Dim objDReader As OleDbDataReader
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & Server.MapPath("db\manuali.mdb")
    Dim objConn As New OleDbConnection(strConn)
    objConn.Open()
    Dim strQuery As string = "insert into manuali (autore,titolo,id_arg,descrizione,percorso,nome_fi le)values('" & autore.text & "','" & new_tit.text & "'," & argomento.value & ",'" & new_desc.value & ",'" & strPercorsoFileUpload & "','" & strFile & "')"
    'Dim objCom As new OleDbCommand(strQuery,objConn)
    'objDReader=objCom.executeReader()
    objConn.close()
    response.write (strQuery)
    End Sub
    </code>

    Il mio problema è che non viene rilevata la scelta dell'utente nella select 'argomento', ma viene sempre letto il primo valore cioè quello selected per default!
    Potreste dirmi dove sbaglio e darmi suggerimenti. Glazie a tutti


  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    credo, ma non ho visto bene, che dovresti crearti la select solo la prima volta e non nel postback. Perciò, If not me.IsPostBack then crea select altrimenti altro fine se.
    Pietro

  3. #3
    usa una dropdownlist invece del html form. l'associ direttamente ad un dataset o al dreader ( come vuoi te ).

    a questo punto non ti resta che
    specificare nella clausola where della SQL

    codice:
    where xxx = dropdownlist.selecteditem.value

  4. #4
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    vedi se ti può servire
    codice:
    		<form id="Form1" method="post" runat="server">
    			<SELECT id="Select1" name="Select1" runat="server"></SELECT>
    			<asp:Button id="Button2" runat="server" Text="Refresh"></asp:Button>
    		</form>
    codice:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Inserire qui il codice utente necessario per inizializzare la pagina
            If Not Me.IsPostBack Then
                BindData()
            End If
        End Sub
    
        Private Sub BindData()
            Dim dt As DataTable = Libreria.GetDataTable(StringaConnessione, "SELECT ID, TESTO FROM CAMPI ORDER BY ID")
            Me.Select1.DataSource = dt
            Me.Select1.DataTextField = "testo"
            Me.Select1.DataValueField = "id"
            Me.Select1.DataBind()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            'stampo il value
            PrintLn(Me.Select1.Items.Item(Me.Select1.SelectedIndex).Value)
    
            'stampo il Text
            PrintLn(Me.Select1.Items.Item(Me.Select1.SelectedIndex).Text)
    
            'stampo il value
            PrintLn(Me.Select1.Value)
        End Sub
    Pietro

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.