Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 02, 2012 01:16 PM by superguppie
Feb 29, 2012 11:28 PM|LINK
I have 3 tier data model. I have class for Patient and PatientDB to get Patient data based on ID. In PatientDB there is one static function which returns Patient object. When I get Patient object I would like to display it. I thought at the beginning about
labels for each field, but finally I tried to bind Patient object to detailsView control. Of course it does not work as DataSource for DV control requires IEnumerable. The question is how should I convert my Patient object to IEnumerable? Maybe there is another
way to do this? Or finally maybe I should forget to use DetailsView to display ma Patient object and use labels as previously planned. Thanks for any ideas...
Mar 01, 2012 04:44 AM|LINK
Create a new Generic List and add the Patient object to the list..
List<Patient> myListOfPatient = new List<Patient>();
DetailsView1.DataSource = myListOfPatient ;
Mar 01, 2012 06:41 AM|LINK
Do I need to create a list even knowing that I will neve have more than one patient object there?
Mar 01, 2012 01:32 PM|LINK
Well, it doesn't have to be a List. An array will work just as well. As long as it implements IEnumerable, and the items in it are of the patient type.
This is because of the general way Data Controls work. DataSource has to be IEnumerable. Each Item in the Data Control will be bound to an Item from the IEnumerable. DetailsView will only show one Item at a time. But still, it will work according to this
Upside to it is that you can use Paging to step through the Items one at a time.
Downside is that you always have to "pack" a single object in an IEnumerable. Small price to pay for the benefits, if you ask me.
Mar 01, 2012 07:24 PM|LINK
Thanks for explanation. It makes sense thought. Last question here. Do you think that it is worth to bind to detailsView if I want only to display choosen object. Is it not better solution to display object fields in separate labels?
Mar 02, 2012 01:16 PM|LINK
I think it is. DetailsView can do a lot for you. Minimal coding needed. Good for mainenance.