Link to home
Start Free TrialLog in
Avatar of Gaiala
GaialaFlag for Germany

asked on

asp.net bind textBox to an object

Hello together,

I want to bind a textBox to an object like the following.

Thank you in advance.
Public Class Test
    Private strTest As String
    Public Property usingTest() As String
        Get
            Return Me.strTest 
        End Get
        Set(ByVal value As String)
            Me.strTest = value
        End Set
    End Property
End class
 
'in another class I generate a TextBox
dim tst as new Test
dim txt01 as new TextBox
 
'something like this
'txt01.Text = "<%# Container.DataItem('tst.usingTest') %>"
'txt01.Text = "<%#tst.usingTest%>"

Open in new window

Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

Hi, something like this?
dim tst as new Test
dim txt01 as new TextBox
 
txt01.Text = tst.usingTest

Open in new window

Avatar of Gaiala

ASKER

no that does not work.
Do you get an error?
Avatar of Gaiala

ASKER

I don't get an error.  The problem is that at this time tst.usingTest is always  emty.
The textbox belongs to a templatefield (gridView).
Ok, but when are you setting it's value? the code I showed was just an example of how to call the usingTest property. At some point you would need to do something like this:
tst.usingTest = "Some Value"

Open in new window

Avatar of Gaiala

ASKER

here my code
'the class FillObjects
For Each ndChild As XmlNode In ndItem.ChildNodes
   xmlTest = New GridContents
   '...
   xmlTest.stateProperty() = tempString 'has a value
   '....
 
'the class GridContents
 Public Property stateProperty() As String()
        Get
            Return Me.strState
        End Get
        Set(ByVal value() As String)
            Me.strState= value
        End Set
 End Property
 
'I have GridView which contains TemplateFields
 
Dim templField As New TemplateField
templField.HeaderText = strHeaderText
templField.Visible = True
templField.ItemTemplate = New TestTemplate
testGrid .Columns.Add(templField)
 
'the implementation of TestTemplate looks like
Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Dim txtControl As New TextBox
        Dim lblControl As New Label
         lblControl.ID = "lblCon"
        txtControl.ID = "txtBox"
        Dim cl_TC As New GridContents
        Dim tempStr() As String
      
        txtControl.Text = cl_TC.StateProperty 'the value is always empty
        container.Controls.Add(lblControl) 
        container.Controls.Add(txtControl)
 End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Oliver Amaya
Oliver Amaya
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gaiala

ASKER

oh sure, you are right!!!
so where is no possibility to get the already instantiated objects to bind on the textbox?
Depends on what you're doing after you set the value in the code below, is this getting saved to an xml file after you set the value? if so you would have to read the contents of that XML file whenever you want to set the textbox's value.
For Each ndChild As XmlNode In ndItem.ChildNodes
   xmlTest = New GridContents
   '...'
   xmlTest.stateProperty = tempString 'has a value'
   '....'

Open in new window