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...
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
rule.
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.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Marked as answer by serberto on Mar 01, 2012 08:11 PM
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?
I think it is. DetailsView can do a lot for you. Minimal coding needed. Good for mainenance.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
serberto
Member
66 Points
46 Posts
Bind object to DetailsView
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...
object DetailsView ienumerable
mameenkhn
Contributor
2026 Points
391 Posts
Re: Bind object to DetailsView
Mar 01, 2012 04:44 AM|LINK
Create a new Generic List and add the Patient object to the list..
object DetailsView ienumerable
--------------------------------------------------
Muhammad Amin
محمد امين
serberto
Member
66 Points
46 Posts
Re: Bind object to DetailsView
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?
superguppie
All-Star
48225 Points
8679 Posts
Re: Bind object to DetailsView
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 rule.
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.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
serberto
Member
66 Points
46 Posts
Re: Bind object to DetailsView
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?
superguppie
All-Star
48225 Points
8679 Posts
Re: Bind object to DetailsView
Mar 02, 2012 01:16 PM|LINK
I think it is. DetailsView can do a lot for you. Minimal coding needed. Good for mainenance.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.