L
Lauchlan M
Hi
I have a drop down list and I want to populate it from a datareader.
I have this code
<<
Connection.Open();
dtrHospitalList = Cmd_HospitalList.ExecuteReader();
lstHospital.DataSource = dtrHospitalList;
lstHospital.DataBind();
There are two problems with this: first I would need to specify which of the
fields from the data reader goes in to the text of the drop down list (in
this case this field is 'HospitalName') and which field goes in to the
selectedvalue value (in this case 'HospitalCode').
Secondly, it just doesn't like it anyway! <g> - it tells me "Exception
Details: System.ArgumentException: An invalid data source is being used for
lstHospital. A valid data source must implement either IListSource or
IEnumerable."
So what is the correct code to databind a drop-down-list to a datareader? Or
should I be using something else instead, eg a dataset filled by a
dataadapter?
Thanks!
Lauchlan M
I have a drop down list and I want to populate it from a datareader.
I have this code
<<
Connection.Open();
dtrHospitalList = Cmd_HospitalList.ExecuteReader();
lstHospital.DataSource = dtrHospitalList;
lstHospital.DataBind();
There are two problems with this: first I would need to specify which of the
fields from the data reader goes in to the text of the drop down list (in
this case this field is 'HospitalName') and which field goes in to the
selectedvalue value (in this case 'HospitalCode').
Secondly, it just doesn't like it anyway! <g> - it tells me "Exception
Details: System.ArgumentException: An invalid data source is being used for
lstHospital. A valid data source must implement either IListSource or
IEnumerable."
So what is the correct code to databind a drop-down-list to a datareader? Or
should I be using something else instead, eg a dataset filled by a
dataadapter?
Thanks!
Lauchlan M