Hello,
I am creating the form controls at runtime in my ASPX page on a button click event in a table designed at design time. The ID of Table is (tbl) . To this table I am adding the rows, cells and the controls called dropdownlist and a textbox in a cell at runtime.
When the user fills the values click for save button, I want to get the values from the dropdownlist saves into my database.
The code I wrote is as follows:
Private Sub btnADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADD.Click
Dim i As Short
Dim row As TableRow
Dim cell As TableCell
Dim ddl As DropDownList
Dim lst As ListBox
For i = 1 To TxtValue.Text
row = New TableRow
' ADD FUNCTIONS
ddl = New DropDownList
ddl.ID = "function" & i
ddl.DataTextField = "FLD_FUNCTION_DISPLAY_NAME
"
ddl.DataValueField = "FLD_FUNCTION_NAME"
ddl.DataSource = objDS
ddl.DataBind()
cell = New TableCell
cell.Controls.Add(ddl)
row.Cells.Add(cell)
' ADD FIELD TEXT
cell = New TableCell
cell.Text = "FIELD" & i
row.Cells.Add(cell)
' ADD RETURN TYPE
cell = New TableCell
lst = New ListBox
lst.SelectionMode = ListSelectionMode.Single
lst.Rows = 1
lst.ID = "return" & i
Dim lstItem As ListItem
lstItem = New ListItem
lstItem.Value = "1"
lstItem.Text = "TRUE"
lst.Items.Add(lstItem)
lstItem = New ListItem
lstItem.Value = "0"
lstItem.Text = "FALSE"
lst.Items.Add(lstItem)
cell.Controls.Add(lst)
row.Cells.Add(cell)
' ADD and / or
cell = New TableCell
If Not i = TxtValue.Text Then
lst = New ListBox
lst.SelectionMode = ListSelectionMode.Single
lst.Rows = 1
lst.ID = "andor" & i
lst.Items.Add("AND")
lst.Items.Add("OR")
cell.Controls.Add(lst)
End If
row.Cells.Add(cell)
tbl.Rows.Add(row)
Next
End sub
Now I am retreiving the values inside a dropdownlist as follows:
Private Sub btnSAVE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSAVE.Click
Dim lstBox As ListBox
For
For i = 1 To txtNumberOfRows.Text
lstBox = Page.FindControl("Form1").
FindContro
l("tbl").F
indControl
("row" & i).FindControl("cell" & i).FindControl("lstreturn"
& i)
Next
End sub
But I am getting the value of lstBox as nothing.
Will anyone give me the solution for this?
Looking for a kindly help.
Thank you
Nilesh