Dropdownlist en asp.net

cs_ravak31 Messages postés 4 Date d'inscription jeudi 5 juillet 2007 Statut Membre Dernière intervention 30 mai 2008 - 28 mai 2008 à 09:15
cs_ravak31 Messages postés 4 Date d'inscription jeudi 5 juillet 2007 Statut Membre Dernière intervention 30 mai 2008 - 29 mai 2008 à 07:45
bjr, je suis debutante en asp.net et j'aimerai savoir comment faire si je selectionne une valeur id dans un dropdownlist (lie a la base de donnees)apres cela s'affichera dans un autre champ le contenu correspondant du id. Voici le code que j'ai trouve mais ca ne marche pas:
rivate Sub ddl_CDT_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_CDT.SelectedIndexChanged
        Dim objreader_ddl_CDT As SqlClient.SqlDataReader
        Dim objparam_ddl_CDT As SqlClient.SqlParameter
        Dim connectstring_ddl_CDT As String = "uid=sa;password=ravaka;database=mtpm_patrimoine;server=(local)"
        Dim connection_ddl_CDT As SqlClient.SqlConnection = New SqlClient.SqlConnection(connectstring_ddl_CDT)
        Dim objcommand_ddl_CDT As SqlClient.SqlCommand = New SqlClient.SqlCommand("select * from chef_depot where ([mailto:num_matricule_CDT=@num_matricule num_matricule_CDT=@num_matricule]", connection_ddl_CDT)
        objparam_ddl_CDT = objcommand_ddl_CDT.Parameters.Add("@num_matricule", SqlDbType.VarChar, 50)
        objparam_ddl_CDT.Direction = ParameterDirection.Input
        objparam_ddl_CDT.Value = ddl_CDT.SelectedItem.Text
        Try
            objcommand_ddl_CDT.Connection.Open()
            objreader_ddl_CDT = objcommand_ddl_CDT.ExecuteReader(CommandBehavior.Default)
        Catch ex As Exception
            Response.Write("error to connect into database$" + "
")
        End Try
        While objreader_ddl_CDT.Read
            If (objreader_ddl_CDT.GetValue(0) <> "") Then
                txt_nom_CDT.Text = objreader_ddl_CDT.GetValue(1)
            End If
        End While
        objreader_ddl_CDT.Close()
        objcommand_ddl_CDT.Connection.Close()
    End Sub
Merci a tout ce qui veut me repondre!

2 réponses

GillouXman Messages postés 561 Date d'inscription mardi 4 mars 2008 Statut Membre Dernière intervention 10 juin 2010
28 mai 2008 à 10:07
il passe dans le code ou pas ?

as tu activé l'autopostback sur la dropdown ?
0
cs_ravak31 Messages postés 4 Date d'inscription jeudi 5 juillet 2007 Statut Membre Dernière intervention 30 mai 2008
29 mai 2008 à 07:45
Bonjour, merci à toi de me répondre GillouXman, oui j'ai déjà activé l'autopostback du dropdown et quand je lance le browser, il m'envoye une erreur:



Object reference not set to an instance of an object.



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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 563:            Response.Write("error to connect into database$" + "
")
Line 564:        End Try
Line 565:        While objreader_ddl_CDT.Read
Line 566:            If (objreader_ddl_CDT.GetValue(0) <> "") Then
Line 567:                txt_nom_CDT.Text = objreader_ddl_CDT.GetValue(1)

0
Rejoignez-nous