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

Discussion in 'ASP .Net' started by Ali M, Feb 15, 2005.

  1. Ali M

    Ali M Guest


    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...

    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)")
    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))
    oCol = New DataColumn("Name", GetType(String))

    t = 10
    For i = 1 To t
    iRow = oTable.NewRow()
    iRow.Item(0) = i
    iRow.Item(1) = "Row " & i.ToString()
    oRow = oTable.Rows(3)
    End Sub
    End Class
    Ali M, Feb 15, 2005
    1. Advertisements

  2. Ali M

    Mark Sandfox Guest

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

    SIndex = 'integer of the row you wish
    drStates = dvStates.Item(SIndex)
    Mark Sandfox, Feb 15, 2005
    1. Advertisements

  3. Ali M

    Ali M Guest

    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

    Ali M, Feb 15, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.