Fill the listbox

  • 14 years ago

    Hi all!!!

    I want fill my listbox with a dropdownlist..But it doesn't work..When i select an item of my dropdownlist,my listbox was not filled..

    I can't find the error,pls help meeee....

    Thanks all!

    Here is my coding:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Not IsPostBack Then

    ChargerListeexploitant()

    End If

    End Sub

    Sub ChargerListeexploitant()

    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=INSRVSN2\GESTION ;Initial Catalog=Dev_GI2;uid=dev_gi2;password=dev_gi2"

    Dim myConnection As SqlConnection = New SqlConnection(strConnexion)

    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

    '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 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")

    Try

    myConnection.Open()

    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

    End If

    End Sub

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky