Bonjour a tous,
je vous présente je suis débutante et j ai besoin de vos aides.
Je veux récupérer les contenu de label et tetxbox checkbox dropdownsListe . deja crée dynamiquement au niveau de Load_page
les labels contient les nom des champs de table de donnée et les autres controllers sont construit selon le type de champs au niveau de BD . par exemple si le type c'est nvarchar je crée un textbox si bit un check box ainsi de suite.
j'ai une bouton qu'elle ^permet de valider la raquette insert into le table construit des début.
je veux savoir comment je peux récupérer les champs et leur contenu par l’intermédiaire par leur id .
Merci beaucoup
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tableName1 = Request.Params("tableName")
'Response.Write(tableName1)
cn.ConnectionString = "Data Source=DESKTOP-HIJUTE7\MYSQLDB;Initial Catalog=testDB;Integrated Security=True"
cn.Open()
cmd.CommandText = "SELECT TABLE_NAME,COLUMN_NAME, DATA_TYPE,COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='" & tableName1 & "' "
cmd.Connection = cn
dr = cmd.ExecuteReader
nbreEnregistrement = 0
Dim tb_table As Table = New Table()
tb1.Controls.Add(tb_table)
While dr.Read()
tableName = dr(0).ToString
lblName.Text = tableName1
Dim tr As TableRow = New TableRow()
Dim tblCols As Integer = 2
Dim tc As TableCell = New TableCell()
dt = dr(2).ToString
tablechamp = dr(1).ToString
Dim txtBox As TextBox = New TextBox()
txtBox.Text = tablechamp
txtBox.ReadOnly = "True"
txtBox.BorderStyle = "1"
txtBox.ID = "champ" & nbreEnregistrement
Response.Write(txtBox.ID)
' ajout control au TableCell
tc.Controls.Add(txtBox)
' ajout TableCell au TableRow
tr.Cells.Add(tc)
'ajout les label au tableau de controls mycontrols
'myControls.Add(txtBox)
If dt = "nvarchar" Or dt = "int" Then
Dim texttype As New TextBox
texttype.ID = "txt" & nbreEnregistrement
Response.Write(texttype.ID)
texttype.Style("Top") = "25px"
texttype.Style("Left") = "100px"
'Add the control to the TableCell
tc.Controls.Add(texttype)
'ajout control lel tableau du control
' myControls.Add(texttype)
' Add the TableCell to the TableRow
tr.Cells.Add(tc)
ElseIf dt = "uniqueidentifier" And dr(3).ToString <> "(newid())" Then
'creation dropdownliste
Dim ddlist As New DropDownList()
ddlist.ID = "drop" & nbreEnregistrement
Response.Write(ddlist.ID)
ddlist.DataValueField = dr(1).ToString
' Add the control to the TableCell
tc.Controls.Add(ddlist)
tr.Cells.Add(tc)
ElseIf dt = "bit" Then
'case à cocher
Dim checkBox As New CheckBox()
checkBox.Checked = True
checkBox.ID = "check" & nbreEnregistrement
Response.Write(checkBox.ID)
' Add the control to the TableCell
tc.Controls.Add(checkBox)
' Add the TableCell to the TableRow
tr.Cells.Add(tc)
End If
' Add the TableRow to the Table
tb_table.Rows.Add(tr)
' End If
nbreEnregistrement = nbreEnregistrement + 1
End While
cn.Close()
Dim btnValid As Button = New Button()
btnValid.Text = "Enregistrer"
btnValid.Enabled = "True"
AddHandler btnValid.Click, AddressOf ValidButton_Clic
tb1.Controls.Add(btnValid)
End Sub
EDIT : Ajout des balises de code (la coloration syntaxique). Explications disponibles ici : ICI
Bonsoir, et merci à Nhenri d'avoir rendu ton code lisible (voir l'encadré bleu qu'il a rajouté).
Peux tu montrer une capture d'écran de ce que ça donne?