Quinve
Messages postés4Date d'inscriptionmardi 23 octobre 2001StatutMembreDernière intervention25 décembre 2007
-
25 nov. 2003 à 00:29
cs_rabbiwan
Messages postés151Date d'inscriptionmercredi 18 septembre 2002StatutMembreDernière intervention22 février 2007
-
29 déc. 2004 à 12:07
Bonjour,
sur une page j'ai une ListBox. Je cherche à récupérer le texte de l'élément sur lequel je clique.
Voici mon code :
Code:
Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
TextBox1.text=ListBox1.SelectedItem.Text
End Sub
Voici la page en HTML :
Code:
Lorsque je clique sur un élément, une erreur apparaît :
Citation:
Server Error in '/Annuaire' Application.
--------------------------------------------------------------------------------
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 56:
Line 57: Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Line 58: TextBox1.text=ListBox1.SelectedItem.Text
Line 59: End Sub
Line 60:
Je pense qu'après le postback, il n'y a pas d'élément sélectionné, d'où l'erreur, car quand je teste avec seulement Code:
TextBox1.text=ListBox1.SelectedIndex
, j'ai le résultat -1 qui apparait.
Alors comment puis-je solutionner ce problème ?
Merci d'avance.
Raph