Hi Mike,
You should be able to bind to a textbox by binding the page. Here's some
code that might give you the idea. Let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
' From Ken Cox Microsoft MVP [ASP.NET]
If Not IsPostBack Then
' Create a dataset
Dim ds As New DataSet
' Add a table to the dataset
ds.Tables.Add(C reateDataSource ())
' Create a filter so that we only get one row
ds.Tables(0).De faultView.RowFi lter = "IntegerVal ue = 5"
' Pass the dataset and an expression to DataBinder.Eval
' so that it returns the string called StringValue in
' the default dataview
TextBox1.Text = DataBinder.Eval (ds, _
"Tables(0).Defa ultView(0).Stri ngValue")
' Bind everything on the page
Page.DataBind()
End If
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArg s) _
Handles Button1.Click
Label1.Text = TextBox1.Text
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
<form id="Form1" method="post" runat="server">
<p>
<asp:textbox id="TextBox1" runat="server"> </asp:textbox></p>
<p>
<asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
<p>
<asp:label id="Label1" runat="server"> </asp:label></p>
</form>
"MrMike" <Mr****@discuss ions.microsoft. com> wrote in message
news:B1******** *************** ***********@mic rosoft.com...
Hi. I have a dataset on my webform which I successfully fill by calling a
Sub that occurs after the Page_Load. My question is - I have a textbox
control which I need to populate with the contents of one of the Dataset
columns. If I set set the binding properties using the properties window,
this isn't successfull since the textbox attempts to bind at page_load, at
which time the dataset is not filled.
How can I use VB code to specify that the textbox's text property should
be
set to a column within the dataset? Thanks!