Bonjour,
j'ai une liste de catégories de produits, chaque catégorie contenant plusieurs produits classés dans ma base de données sql
voici le code :
le code pour afficher :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 <div id="Milieu"> <ul> <asp:Repeater id="CatList" runat="server" OnItemDataBound="R1_ItemDataBound"> <ItemTemplate> <li> <asp:Label ID="CatId" text='<%# DataBinder.Eval(Container.DataItem, "CatId") %>' Visible=False Runat=server> </asp:Label> <asp:Label ID="NomProd" Visible=False Runat=server> </asp:Label> <asp:HyperLink id="HyperLink1" Text='<%# DataBinder.Eval(Container.DataItem, "NomCat") %>' NavigateUrl='<%# "Categories.aspx?CatID=" & DataBinder.Eval(Container.DataItem, "CatID") & "&selectmenu=" & Container.ItemIndex %>' runat="server" /> <aspropDownList ID="ProdList" AutoPostBack=True OnSelectedIndexChanged="Selection_change" Runat="server"> </aspropDownList> </li> </ItemTemplate> </asp:Repeater></ul> </div>
Ma page s'affiche correctement mais lorsque je sélectionne un produit dans ma dropdownlist j'ai un bug javascript et mon autopostback ne se fait pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then Dim Produits As Altearah.HuilesRares.ProduitDB = New Altearah.HuilesRares.ProduitDB Dim Adapter As SqlDataAdapter Adapter = Produits.CatListBylg(CInt(Session("lg"))) Dim CatTable As DataTable CatTable = New DataTable Adapter.Fill(CatTable) CatList.DataSource = CatTable.DefaultView CatList.DataBind() End If End Sub Public Sub R1_ItemDataBound(ByVal Sender As Object, ByVal e As RepeaterItemEventArgs) Handles CatList.ItemDataBound If (e.Item.ItemType = ListItemType.Item) Or _ (e.Item.ItemType = ListItemType.AlternatingItem) Then 'Liste des produits Dim Cat As Integer Cat = CInt(CType(e.Item.FindControl("CatId"), Label).Text) Dim Produits As Altearah.HuilesRares.ProduitDB = New Altearah.HuilesRares.ProduitDB CType(e.Item.FindControl("ProdList"), DropDownList).DataSource = Produits.ListDistProdByCat(Cat, "NomProd") CType(e.Item.FindControl("ProdList"), DropDownList).DataTextField = "NomProd" CType(e.Item.FindControl("ProdList"), DropDownList).DataValueField = "CodeProd" CType(e.Item.FindControl("ProdList"), DropDownList).Items.Insert(0, New ListItem("", "<--Liste des Produits-->")) CType(e.Item.FindControl("ProdList"), DropDownList).DataBind() End If End Sub Public Sub Selection_Change(ByVal sender As Object, ByVal e As EventArgs) Dim nom As DropDownList nom = CType(sender, DropDownList) Dim val As String val = nom.SelectedValue End Sub
Je ne comprends pas d'où vient l'erreur
autre problème plus mineur, je n'arrive pas à afficher dans mes dropdownlist une première ligne neutre
Merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part CType(e.Item.FindControl("ProdList"), DropDownList).Items.Insert(0, New ListItem("", "<--Liste des Produits-->"))
Partager