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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
Dim al As New ArrayList()
<Serializable()> Private Structure bt
Dim id As String
Dim selval As Int16
Dim categ As Int16
End Structure
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If ViewState("al") Is Nothing Then
ViewState("al") = al
End If
If IsPostBack Then
Try
Dim item As Object
al = CType(ViewState("al"), ArrayList)
For Each item In al
Dim NewLst As New DropDownList
Dim nbCell As Int16 = tb.Rows(0).Cells.Count
Dim NewCell As New TableCell
tb.Rows(0).Cells.Add(NewCell)
RemplirListeCrea(NewLst, nbCell, item.categ)
tb.Rows(0).Cells(nbCell).Controls.Add(NewLst)
Next
Catch
End Try
Else
Dim param1 As New List(Of DataParametre)
param1.Add(New DataParametre("param1", "0"))
lst_1.Items.Add(New ListItem("Choisir", "C"))
lst_1.Items.Add(New ListItem("Ajouter", "A"))
RemplirListeDer(lst_1, "ListSCateg", param1)
lst_1.AutoPostBack = True
End If
End Sub
Protected Sub lst_1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_1.SelectedIndexChanged
'al = CType(ViewState("al"), ArrayList)
Dim nbCell As Int16 = tb.Rows(0).Cells.Count
Dim nbLst As Int16 = CInt(Right(CType(sender, DropDownList).ID, Len(CType(sender, DropDownList).ID) - 4))
Dim lstEncours As DropDownList = CType(sender, DropDownList)
If nbLst <> nbCell Then
If nbCell = 1 Then
CreaLst(nbCell, lstEncours.SelectedValue, 1)
Else
Dim toto As String = ""
Dim i As Int16 = al.Count + 1
While i > nbLst
al.RemoveAt(i - 2)
tb.Rows(0).Cells.RemoveAt(i - 1)
i -= 1
End While
ViewState("al") = al
nbCell = tb.Rows(0).Cells.Count
CreaLst(nbCell, lstEncours.SelectedValue, 1)
End If
Else
CreaLst(nbCell, lstEncours.SelectedValue, 1)
End If
End Sub
Sub CreaLst(ByVal nbCell As Short, ByVal categ As String, ByVal selval As String)
Dim NewCell As New TableCell
tb.Rows(0).Cells.Add(NewCell)
Dim NewLbl As New Label
Dim NewLst As New DropDownList
Select Case categ
Case "A"
NewLbl.Text = "J'ajoute une entrée"
tb.Rows(0).Cells(nbCell).Controls.Add(NewLbl)
Case "C"
NewLbl.Text = "Je choisi"
tb.Rows(0).Cells(nbCell).Controls.Add(NewLbl)
Case Else
RemplirListeCrea(NewLst, nbCell, categ)
If NewLst.Items.Count < 3 Then
NewLbl.Text = "Pas de sous catégorie pour cette catégorie."
tb.Rows(0).Cells(nbCell).Controls.Add(NewLbl)
Else
tb.Rows(0).Cells(nbCell).Controls.Add(NewLst)
End If
Try
Dim bt_save As New bt()
bt_save.id = NewLst.ID
bt_save.categ = categ
If IsNothing(al) Then
al = New ArrayList()
End If
al.Add(bt_save)
Catch err As SystemException
err.ToString()
End Try
ViewState("al") = al
End Select
End Sub
Sub RemplirListeCrea(ByVal NewLst As DropDownList, ByVal nbCell As Short, ByVal categ As String)
NewLst.ID = "lst_" & nbCell + 1
Dim param As New List(Of DataParametre)
param.Add(New DataParametre("param1", categ))
NewLst.Items.Add(New ListItem("Choisir", "C"))
NewLst.Items.Add(New ListItem("Ajouter", "A"))
RemplirListeDer(NewLst, "ListSCateg", param)
NewLst.AutoPostBack = True
AddHandler NewLst.SelectedIndexChanged, AddressOf lst_1_SelectedIndexChanged
End Sub |