473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Data Bind for textbox

I have bind a dataset, DentistDataSet1, to TextBox, txtLastName, by set the
textbox property (databindings--> simple binding--> ... -->LastName) and also
bind it to a dropdown list, DropdownList1 with datasource (DentistDataSet1),
DataMember (Dentists), and DataTextField (DentistID), and AutoPostBack(true).
The settings are done by Visual .NET studio 2003.

Also I have the following event code and expect the FirstName and LastName
would be changed with selecting another DentistID in the dropdown list.
-------
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")

End Sub
------

When I select a new DentistID, I got the following error:
------
Exception Details: System.IndexOutOfRangeException: There is no row at
position 1.

Source Error:
Line 182: 'txtLastName.DataBind()
Line 183: 'txtFirstName.DataBind()
Line 184: txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
Line 185: txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")
Line 186:
------
Any one could help me to figure out the problem? Or what is the correct
steps to set up the properties and coding to get my expected result?

Thank you very much

David
Nov 19 '05 #1
3 1708
You have to refill your dataset on postback...it doesn't magically preserve
its values...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"david" <da***@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I have bind a dataset, DentistDataSet1, to TextBox, txtLastName, by set the textbox property (databindings--> simple binding--> ... -->LastName) and also bind it to a dropdown list, DropdownList1 with datasource (DentistDataSet1), DataMember (Dentists), and DataTextField (DentistID), and AutoPostBack(true). The settings are done by Visual .NET studio 2003.

Also I have the following event code and expect the FirstName and LastName
would be changed with selecting another DentistID in the dropdown list.
-------
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")

End Sub
------

When I select a new DentistID, I got the following error:
------
Exception Details: System.IndexOutOfRangeException: There is no row at
position 1.

Source Error:
Line 182: 'txtLastName.DataBind()
Line 183: 'txtFirstName.DataBind()
Line 184: txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
Line 185: txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")
Line 186:
------
Any one could help me to figure out the problem? Or what is the correct
steps to set up the properties and coding to get my expected result?

Thank you very much

David

Nov 19 '05 #2
Thank you, Karl:
I have added code to Page_load as follows, but I still got error.
-----------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
SqlDataAdapter1.Fill(DentistDataSet1)
DropDownList1.DataBind()
txtLastName.DataBind()
txtFirstName.DataBind()
txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")

End If

SqlDataAdapter1.Fill(DentistDataSet1)
'DropDownList1.DataBind()
txtLastName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("LastName"))
txtFirstName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("FirstName"))

End Sub
----------------------
Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:
Line 178: SqlDataAdapter1.Fill(DentistDataSet1)
Line 179: 'DropDownList1.DataBind()
Line 180: txtLastName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("LastName"))
Line 181: txtFirstName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("FirstName"))
Line 182:

-------------------------

"Karl Seguin" wrote:
You have to refill your dataset on postback...it doesn't magically preserve
its values...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"david" <da***@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I have bind a dataset, DentistDataSet1, to TextBox, txtLastName, by set

the
textbox property (databindings--> simple binding--> ... -->LastName) and

also
bind it to a dropdown list, DropdownList1 with datasource

(DentistDataSet1),
DataMember (Dentists), and DataTextField (DentistID), and

AutoPostBack(true).
The settings are done by Visual .NET studio 2003.

Also I have the following event code and expect the FirstName and LastName
would be changed with selecting another DentistID in the dropdown list.
-------
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")

End Sub
------

When I select a new DentistID, I got the following error:
------
Exception Details: System.IndexOutOfRangeException: There is no row at
position 1.

Source Error:
Line 182: 'txtLastName.DataBind()
Line 183: 'txtFirstName.DataBind()
Line 184: txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
Line 185: txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")
Line 186:
------
Any one could help me to figure out the problem? Or what is the correct
steps to set up the properties and coding to get my expected result?

Thank you very much

David


Nov 19 '05 #3
My guess is that lblCurrentIndex.Text isn't an int like you think it is...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"david" <da***@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...
Thank you, Karl:
I have added code to Page_load as follows, but I still got error.
-----------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
SqlDataAdapter1.Fill(DentistDataSet1)
DropDownList1.DataBind()
txtLastName.DataBind()
txtFirstName.DataBind()
txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName")
txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")

End If

SqlDataAdapter1.Fill(DentistDataSet1)
'DropDownList1.DataBind()
txtLastName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("LastName")) txtFirstName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("FirstName")
)
End Sub
----------------------
Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:
Line 178: SqlDataAdapter1.Fill(DentistDataSet1)
Line 179: 'DropDownList1.DataBind()
Line 180: txtLastName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("LastName")) Line 181: txtFirstName.Text =
CStr(DentistDataSet1.Tables(0).Rows(CInt(lblCurren tIndex.Text))("FirstName")
) Line 182:

-------------------------

"Karl Seguin" wrote:
You have to refill your dataset on postback...it doesn't magically preserve its values...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"david" <da***@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I have bind a dataset, DentistDataSet1, to TextBox, txtLastName, by set
the
textbox property (databindings--> simple binding--> ... -->LastName)
and also
bind it to a dropdown list, DropdownList1 with datasource

(DentistDataSet1),
DataMember (Dentists), and DataTextField (DentistID), and

AutoPostBack(true).
The settings are done by Visual .NET studio 2003.

Also I have the following event code and expect the FirstName and

LastName would be changed with selecting another DentistID in the dropdown list. -------
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName") txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName")
End Sub
------

When I select a new DentistID, I got the following error:
------
Exception Details: System.IndexOutOfRangeException: There is no row at
position 1.

Source Error:
Line 182: 'txtLastName.DataBind()
Line 183: 'txtFirstName.DataBind()
Line 184: txtLastName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("LastName") Line 185: txtFirstName.Text =
DentistDataSet1.Tables(0).Rows(DropDownList1.Selec tedIndex)("FirstName") Line 186:
------
Any one could help me to figure out the problem? Or what is the correct steps to set up the properties and coding to get my expected result?

Thank you very much

David


Nov 19 '05 #4

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

Similar topics

2
by: Vijaya | last post by:
Can we bind data to textbox in a headertemplate in a template column of a datagrid? If so please give some code snippets. Thank you
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
2
by: Aspnot | last post by:
I have a TabControl that is on a form that is bound to a DataSet. I bind the dataset to the form in the Form_Load event. The TabControl has 2 TabPages. The first TabPage contains a button and a...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
0
by: Sam | last post by:
Folks.. I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data...
7
by: RolfHerbert | last post by:
Hi all, Source code below. I am using an sqldatasorce to populate a datagrid. I am using datakeyIds. I am interested in two keys which I have added to the datakeyids, however if either of the...
0
by: Cirene | last post by:
I have a formview that is calling a stored procedure (thru an sqldatasource) to update 2 tables. When I execute the update it runs fine, with no errors. But the data does NOT change. Any ideas...
0
by: John Mason | last post by:
Hi, I've been trying for most of the day to get a FormView control to work. I would like to display a single record, based on a unique user id (loginid), which I am retreiving from a cookie. No...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.