473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bind Textbox to DataSet

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!
Nov 19 '05 #1
3 17765
How can I use VB code to specify that the textbox's text property should
be
set to a column within the dataset? Thanks!


If you're using a typed dataset (are you?), you can easily bind the textbox
to a column by setting the "databindin gs" property of the textbox to point
to a column in the typed dataset's defaultView.

You do this design-time.

Then, whenever you fill the typed dataset, you can afterwards call
myTextbox.datab ind(), which will get the data from the datatable.

Hope it helps,
Jeppe Jespersen
Nov 19 '05 #2
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!


Nov 19 '05 #3
Thank you both! I have this working now after learning from your examples.
Thanks...

"Ken Cox [Microsoft MVP]" wrote:
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!


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
384
by: Steve | last post by:
C# I have some combo boxes, full of lookup descriptions. When I retrieve a dataset for my record, the values that need binding to the combos are the actual record IDs that relate to these lookup descriptions. How do I bind them up in this case? Thanks Steve
4
2202
by: David P. Donahue | last post by:
When I bind a dataset to a SQL query that contains a blob field it comes back as a byte array. Is there any way to have it interpreted as a string or somehow convert it to a string? I'm using the blob field to store large amounts of text and I need to be able to interpret it as such. Regards, David P. Donahue ddonahue@ccs.neu.edu
2
9604
by: OldNewbie | last post by:
Hello All I have a textbox control. I would like this text box to automatically update to contain the currently selected item located in a listbox which is on the same form. Do I need a CurrencyManager for this? Can this be done just by manipulating the databindings properties of the textbox? If so, please do give me some hints as to the syntax I would use to fill in that field on the property panel - everything I try is rejected.
4
2582
by: John Rose | last post by:
I have one databound TextBox on a page with one button. The TextBox loads the correct SQL record data but typing a new string into the Textbox fails to change the DataSet. Any ideas? There must be some way to force the edited TextBox to update the DataSet since it appears to not be done automatically. //-------------------------------------------------------------------------- -------------------------- private void Page_Load(object...
0
1452
by: rbutch | last post by:
hey guys got a question. im trying to bind a textbox "at runtime". im creating the conn string, dataset, dataAdapter etc dynamically. and it keeps erroring out. <asp:TextBox ID="txtDay1" Runat="server" TextMode='<%# A39.DataRow%>'></asp:TextBox> now i have no problem doing this if i hard code my connection string, dataadapter, dataset etc and use the method (databinder eval). <asp:TextBox ID="txtDay1" Runat="server"
17
2773
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
1
1402
by: Adam J Knight | last post by:
Hi all, I am assuming there may be a number of ways to bind a text box to a db field using c#. My current approach is: txtPostCode.Text = rdrInstitution.ToString(); Can anyone let me if there is a generally accepted method for databinding a textbox using c#.
3
22092
by: raamay | last post by:
I have a module where i have specified the connection string as below: Public Function Connection() As String Return "Data Source=192.168.0.1,1433;Network Library=DBMSSOCN;Initial Catalog=test;User ID=sa;Password=123456" End Function Then i have a form which has two textboxes. What i am trying to do is bind the two textboxes to a dataset in the following way: Imports System.Data.SqlClient
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.