Binding a dynamic textbox to DataRow.Item(1) value

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
 
M

Mark Sandfox

Dim dvStates as DataView
Dim drStates as System.Data.DataRowView

SIndex = 'integer of the row you wish
drStates = dvStates.Item(SIndex)
tbStates.text(drStates.Item("State"))
 
A

Ali M

Thanks Mark,

But this does not work for me, as it does not use databinding. You
are assigning the value of the column at that particular time to the
text property; what I want is to bind the property to the column in a
DataRow or DataRowView object so that everytime its values are
modified and a DataBind() is called the controls are automatically
updated!

Ali
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top