[VB.NET] DropDownList_SelectedIndexChanged ne trigger pas.
Salut a tous,
J'ai une combo box qui represente mes champs de clef primaire dans une table sql.
Code:
1 2 3 4 5 6 7
| <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Centraide"
DataTextField="Usine" DataValueField="Usine">
</asp:DropDownList>
<asp:SqlDataSource ID="Centraide" runat="server"
ConnectionString="<%$ ConnectionStrings:CentraideConnectionString %>"
SelectCommand="SELECT [Usine] FROM [Usine]"></asp:SqlDataSource> |
J'ai un deuxieme champ dans ma table Usine qui correspond à la description et je veux que selon l'usine que je prend dans mon combo box, la description s'update dans un textbox.
Vu que mon premier item dans mon combo box se nomme 'ALMA', je fais ceci sur mon page load :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Con = New SqlConnection(Centraide.ConnectionString)
Cmd = New SqlCommand("Select Description from Usine where Usine = 'ALMA'", Con)
Da = New SqlDataAdapter(Cmd)
Ds = New DataSet
Da.Fill(Ds)
txt_desc.Text = Ds.Tables(0).Rows(0).Item(0)
End If
End Sub |
Quand mon programme ouvre j'ai bien la description de mon champs 'ALMA'
Ceci fonctionne.
J'utilise ceci pour faire mon update dans mon textbox.
Code:
1 2 3 4 5 6 7 8 9
|
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Con = New SqlConnection(Centraide.ConnectionString)
Cmd = New SqlCommand("Select Description from Usine where Usine = " & DropDownList1.SelectedValue.ToString, Con)
Da = New SqlDataAdapter(Cmd)
Ds = New DataSet
Da.Fill(Ds)
txt_desc.Text = Ds.Tables(0).Rows(0).Item(0)
End Sub |
Et la est le problème, j'ai mis des points d'arrêts dans cet procédure et jamais mon programme entre dedans...
Est-ce que je doit forcer un postback ? si oui, comment ?? :)
Merci :)