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