Bonjour tout le monde!
Mon problème est le suivant:
J'ai un dropdownlist qui me remplit un listbox (les adresses emails)...Et ce que je veux faire,c'est d'envoyer les éléments séléctionnés du listbox dans un textbox à l'aide d'un boutton (c'est mieux aussi sans un boutton,en double cliquant)...J'ai essayé de faire avec un code mais ce la ne fonctionne pas...
Voilà mes lignes de codes:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim oCommand As SqlCommand
Dim oDataAdap As SqlDataAdapter
Dim oDataSet As New DataSet
Dim oDataTable As New DataTable
Dim req As String
Dim strConn As String
Dim strConnexion As String = "Server=ISTPSRN038\INCIDENTS_DES ;Initial Catalog=Dev_GI2;uid=sa;password=incidents"
Dim myConnection As SqlConnection = New SqlConnection(strConnexion)
If Not Page.IsPostBack Then
Dim myCommand As SqlCommand = New SqlCommand("Select GIGR_GROUPE,GIGR_NOM_GROUPE From GI_GROUPE", myConnection)
Dim myDataReader As SqlDataReader
Try
myConnection.Open()
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
myDropDownList.DataSource = myDataReader
myDropDownList.DataBind()
Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())
Finally
If Not myDataReader Is Nothing Then
myDataReader.Close()
End If
myDropDownList.Items.Insert(0, "**Rechercher par Type**")
myDropDownList.SelectedIndex = 0
End Try
End If
'We don't want this code to run when the default item is selected
If Not myDropDownList.SelectedIndex = 0 Then
ListBox1.Visible = True
'oDataAdap = New SqlDataAdapter("select * from GI_GROUPE", conn)
oDataAdap = New SqlDataAdapter("select GIDE_DESTINATAIRE,GIDE_NOM_DESTINATAIRE,GIDE_MAIL_DESTINATAIRE from GI_GROUPE,GI_LISTEDEST,GI_DESTINATAIRE where GI_GROUPE.GIGR_GROUPE=GI_LISTEDEST.GILD_GROUPE and GI_DESTINATAIRE.GIDE_DESTINATAIRE=GI_LISTEDEST.GILD_DESTINATAIRE and GILD_GROUPE=" & myDropDownList.SelectedItem.Value, myConnection)
oDataAdap.Fill(oDataSet, "GI_DESTINATAIRE")
'Dim myDataReader As SqlDataReader
Try
myConnection.Open()
'myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
ListBox1.DataSource = oDataSet
ListBox1.DataValueField = "GIDE_DESTINATAIRE"
ListBox1.DataTextField = "GIDE_MAIL_DESTINATAIRE"
ListBox1.DataBind()
Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())
Finally
If Not oDataAdap Is Nothing Then
myConnection.Close()
End If
End Try
Else
ListBox1.Visible = False
End If
End Sub
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As EventArgs)
Dim i As Integer
'TextBox1.Text = "You Selected" & " "
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected Then
TextBox1.Text = TextBox1.Text & ListBox1.Items(i).Text & "; " & ""
End If
Next
End Sub 'btnSample5_Click
Merci pour votre aide!!!