Data binding in TextBox after dropdown list indexchanged

G

Guest

I have a question in the following. Any one could give me a help?
Thanks
David

The dataset is declared and created at Class level. My source code is here:

Private Sub lstPatientID_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstPatientID.SelectedIndexChanged
txtDebug.Text &= lstPatientID.SelectedIndex.ToString
txtDebug.Text &= lstPatientID.SelectedIndex.ToString
txtLastName.Text =
ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")

When Page_load,
I use Dropdown list index to set all textboses. Now select another item in
Dropdown list, I got the following error at Line 323:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 321: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
Line 322: txtDebug.Text &= lstPatientID.SelectedIndex.ToString
Line 323: txtLastName.Text =
ds.Tables("Patients").Rows(lstPatientID.SelectedIndex)("LastName")

Line: 323
 
G

Guest

ds is a DataSet.
ds.Tables(0) should be ds.Tables("Patients")
"LastName" is the colunm name.
When Page is first loaded, it OK.
That ocurs when I select a new item of dropdown list.
It is supporsed to bind a new set of data display in all other textbox.
Does it mean the dataset ds has disappeared?

Thanks

David
 
K

Karl Seguin

ds wont' automatically survive a postback....are you repopulating it on
postback? Storing it somewhere?

If you have vs.net 2003, debug and step through the code...see what is
null...no point in trying to solve all 3 potential problems until we know
which 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!)
 
G

Guest

Thank you very much.
How to store the dataset as for a postback?
I have .NET 2003. But I never use the debugging tool.

David
 
K

Karl Seguin

David, left click on the left-side column of VS.Net, a red dot should
appear...that's a breakpoint...Alternatively, you can put your cursor on a
line, goto "Debug" --> "New Breakpoint". Now, hit f5 or "Debug" -->
"Start" which should build and start up your application, launching
IE...now you can browse your site as always, but when the code execution
hits any line with a breakpoint, it'll stop at that line...you can use f10
and f11to step over/in functions/lines....you can add "watches" to
values...play with it...you won't regret it...

You either have to reload the dataset, or store it in the Cache or Session
or some place...

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!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top