Salut,
J'aimerai créer dynamiquement plusieurs lugnes de requetes en asp .net et Ajax. durant le chargement de la page Page_Load, on créer la première ligne.
AddPanel(1)
For i As Integer = 2 To PanelCount
AddPanel(i)
Next
ensuite dans la première ligne, il y a un bouton d'ajout pour le deuxième et le bouton suivant
? Comment fait on avoir les valeurs des controls de chaue lignes de requetes
je vou envoie le code
********************Code************************
Private Sub AddPanel(ByVal i As Integer)
If i = 1 Then
Dim btnAdd As New Button()
With btnAdd
.ID = "btn" & i
.Text = "Bouton" & i
.Width = Unit.Pixel(70).Value
AddHandler btnAdd.Click, AddressOf AddNewLine_Click
End With
'Dim btnClear As New Button()
'With btnClear
' .ID = "Clear" & i
' .Text = "Clear" & i
' .Width = Unit.Pixel(50).Value
' .Enabled = False
' AddHandler btnClear.Click, AddressOf ClearHandler_Click
'End With
Dim dbr As New DataStructureReader.DbStructureReader(AppSettings("XmlFile"))
Dim drpList1 As New DropDownList()
With drpList1
.ID = "DropDownList1" & i
'.DataSource = dbr.GetColumnsListByMainTableClass("Person")
'.DataTextField = "DisplayName"
'.DataValueField = "Property"
.Items.Add("ET")
.Items.Add("OU")
.Width = Unit.Pixel(50).Value
.DataBind()
.Enabled = False
End With
Dim drpList2 As New DropDownList()
With drpList2
.ID = "DropDownList2" & i
.DataSource = dbr.GetColumnsListByMainTableClass("Person")
.DataTextField = "DisplayName"
.DataValueField = "Property"
.Width = Unit.Pixel(200).Value
.DataBind()
End With
Dim drpList3 As New DropDownList()
With drpList3
.ID = "DropDownList3" & i
.DataSource = dbr.GetColumnsListByMainTableClass("Person")
.DataTextField = "DisplayName"
.DataValueField = "Property"
.Width = Unit.Pixel(200).Value
.DataBind()
End With
Dim TxtSql As New TextBox()
With TxtSql
.ID = "TxtSql" & i
.Text = "TextBox" & i
.Width = Unit.Pixel(120).Value
End With
Dim tbl As New Table
Dim rw As New TableRow
If tbl.GetType().ToString.Equals("System.Web.UI.WebControls.Table") Then
With tbl
.ID = "Table" & i
.EnableViewState = True
.BorderWidth = Unit.Pixel(1)
.CellSpacing = 0
.CellPadding = 1
.Width = Unit.Percentage(100)
End With
'Dim cll1 As New TableCell
'cll1.Controls.Add(btnClear)
Dim cll2 As New TableCell
cll2.Controls.Add(btnAdd)
Dim cll3 As New TableCell
cll3.Controls.Add(drpList1)
Dim cll4 As New TableCell
cll4.Controls.Add(drpList2)
Dim cll5 As New TableCell
cll4.Controls.Add(drpList3)
Dim cll6 As New TableCell
cll4.Controls.Add(TxtSql)
With rw
'.Cells.Add(cll1)
.Cells.Add(cll2)
.Cells.Add(cll3)
.Cells.Add(cll4)
.Cells.Add(cll5)
.Cells.Add(cll6)
End With
tbl.Controls.Add(rw)
End If
place.Controls.Add(tbl)
Else
Dim btnAdd As New Button()
With btnAdd
.ID = "btn" & i
.Text = "Bouton" & i
.Width = Unit.Pixel(70).Value
AddHandler btnAdd.Click, AddressOf AddNewLine_Click
End With
Dim btnClear As New Button()
With btnClear
.ID = "Clear" & i
.Text = "Clear" & i
.Width = Unit.Pixel(50).Value
AddHandler btnClear.Click, AddressOf ClearHandler_Click
End With
Dim dbr As New DataStructureReader.DbStructureReader(AppSettings("XmlFile"))
Dim drpList1 As New DropDownList()
With drpList1
.ID = "DropDownList1" & i
'.DataSource = dbr.GetColumnsListByMainTableClass("Person")
'.DataTextField = "DisplayName"
'.DataValueField = "Property"
.Items.Add("ET")
.Items.Add("OU")
.Width = Unit.Pixel(50).Value
.DataBind()
End With
Dim drpList2 As New DropDownList()
With drpList2
.ID = "DropDownList2" & i
.DataSource = dbr.GetColumnsListByMainTableClass("Person")
.DataTextField = "DisplayName"
.DataValueField = "Property"
.Width = Unit.Pixel(200).Value
.DataBind()
End With
Dim drpList3 As New DropDownList()
With drpList3
.ID = "DropDownList3" & i
.DataSource = dbr.GetColumnsListByMainTableClass("Person")
.DataTextField = "DisplayName"
.DataValueField = "Property"
.Width = Unit.Pixel(200).Value
.DataBind()
End With
Dim TxtSql As New TextBox()
With TxtSql
.ID = "TxtSql" & i
.Text = "TextBox" & i
.Width = Unit.Pixel(120).Value
End With
Dim tbl As New Table
Dim rw As New TableRow
If tbl.GetType().ToString.Equals("System.Web.UI.WebControls.Table") Then
With tbl
.ID = "Table" & i
.EnableViewState = True
.BorderWidth = Unit.Pixel(1)
.CellSpacing = 0
.CellPadding = 1
.Width = Unit.Percentage(100)
End With
Dim cll1 As New TableCell
cll1.Controls.Add(btnClear)
Dim cll2 As New TableCell
cll2.Controls.Add(btnAdd)
Dim cll3 As New TableCell
cll3.Controls.Add(drpList1)
Dim cll4 As New TableCell
cll4.Controls.Add(drpList2)
Dim cll5 As New TableCell
cll4.Controls.Add(drpList3)
Dim cll6 As New TableCell
cll4.Controls.Add(TxtSql)
With rw
.Cells.Add(cll1)
.Cells.Add(cll2)
.Cells.Add(cll3)
.Cells.Add(cll4)
.Cells.Add(cll5)
.Cells.Add(cll6)
End With
tbl.Controls.Add(rw)
End If
place.Controls.Add(tbl)
End If
End Sub
Private Sub btnClearAllControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Clear all the controls.
place.Controls.Clear()
' Reset the number of controls.
PanelCount = 0
End Sub
Private Sub ClearHandler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Reset the number of controls.
'If TypeOf sender Is Button Then
If place.Controls.Count > 0 Then
If PanelCount >= 2 Then
place.Controls.RemoveAt(place.Controls.Count - 1)
PanelCount -= 1
Else
MsgBox("Pas de Bouton supplementaire")
End If
End If
'End If
End Sub
Private Sub AddNewLine_Click(ByVal sender As Object, ByVal e As EventArgs)
'Vérifier d'abord que le type de control qui envoye l'écènement
'est un bouton. Ceci est primordiale avant que ce control soit
'attache à ce type d'évènement
If TypeOf sender Is Button Then
If PanelCount < 10 Then
PanelCount += 1
AddPanel(PanelCount)
End If
Else
MsgBox("Ce ci n'est pas un bouton")
End If
End Sub
Private Property PanelCount() As Integer
Get
PanelCount = 1
If ViewState("PanelCount") IsNot Nothing Then
PanelCount = CType(ViewState("PanelCount"), Integer)
End If
Return PanelCount
End Get
Set(ByVal value As Integer)
ViewState("PanelCount") = value
End Set
End Property
********************************Code*********************
Merci
