A
Ali M
Hi,
I am creating a TextBox dynamically at runtime within a Panel, and I
want to bind its Text property to a DataColumn in a DataRow. What is
the correct method for doing this... The following code does not
populate the textbox at all...
Thanks in advance...
Ali
Public Class Test9
Inherits System.Web.UI.Page
Public oRow As DataRow
....
Private Sub pnl_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles pnl.Init
Dim oText As TextBox
oText = New TextBox
oText.ID = "mytext"
oText.Width = Unit.Pixel("200")
oText.Height = Unit.Pixel("25")
oText.Style.Add("position", "absolute")
oText.Style.Add("top", "20px")
oText.Style.Add("left", "20px")
oText.Text = DataBinder.Eval(oRow, "Item(1)")
pnl.Controls.Add(oText)
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim oTable As New DataTable
Dim oCol As DataColumn
Dim iRow As DataRow
Dim i, t As Integer
oCol = New DataColumn("ID", GetType(Int32))
oTable.Columns.Add(oCol)
oCol = New DataColumn("Name", GetType(String))
oTable.Columns.Add(oCol)
t = 10
For i = 1 To t
iRow = oTable.NewRow()
iRow.Item(0) = i
iRow.Item(1) = "Row " & i.ToString()
oTable.Rows.Add(iRow)
Next
oRow = oTable.Rows(3)
DataBind()
End Sub
End Class
I am creating a TextBox dynamically at runtime within a Panel, and I
want to bind its Text property to a DataColumn in a DataRow. What is
the correct method for doing this... The following code does not
populate the textbox at all...
Thanks in advance...
Ali
Public Class Test9
Inherits System.Web.UI.Page
Public oRow As DataRow
....
Private Sub pnl_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles pnl.Init
Dim oText As TextBox
oText = New TextBox
oText.ID = "mytext"
oText.Width = Unit.Pixel("200")
oText.Height = Unit.Pixel("25")
oText.Style.Add("position", "absolute")
oText.Style.Add("top", "20px")
oText.Style.Add("left", "20px")
oText.Text = DataBinder.Eval(oRow, "Item(1)")
pnl.Controls.Add(oText)
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim oTable As New DataTable
Dim oCol As DataColumn
Dim iRow As DataRow
Dim i, t As Integer
oCol = New DataColumn("ID", GetType(Int32))
oTable.Columns.Add(oCol)
oCol = New DataColumn("Name", GetType(String))
oTable.Columns.Add(oCol)
t = 10
For i = 1 To t
iRow = oTable.NewRow()
iRow.Item(0) = i
iRow.Item(1) = "Row " & i.ToString()
oTable.Rows.Add(iRow)
Next
oRow = oTable.Rows(3)
DataBind()
End Sub
End Class