This is a bit of a mix between asp.net and c#, but I thought I'd try
here first.
I have a number of objects (imagine products) in an IList that I want
to render in the UI. They all inherit from the same base class. The
individual classes have extra attributes, for example one might have
weight, another color.
I want a generic way to render these in the UI, without the need of a
huge switch statement. Should each object know how to render itself
for instance?
Any implemented examples around the net would be good. Thanks.
|
|
0
|
|
|
|
Reply
|
Spondishy
|
4/5/2010 8:41:02 AM |
|
Spondishy wrote:
> This is a bit of a mix between asp.net and c#, but I thought I'd try
> here first.
>
> I have a number of objects (imagine products) in an IList that I want
> to render in the UI. They all inherit from the same base class. The
> individual classes have extra attributes, for example one might have
> weight, another color.
>
> I want a generic way to render these in the UI, without the need of a
> huge switch statement. Should each object know how to render itself
> for instance?
>
> Any implemented examples around the net would be good. Thanks.
The question is a classic example of where you should use some form of
polymorphism.
You can either define an interface that each object implements, or the
base class can include a virtual method for rendering that each object
overrides.
A Google search can turn up a wealth of information on both, as far as
examples go.
Pete
|
|
0
|
|
|
|
Reply
|
Peter
|
4/5/2010 9:33:43 AM
|
|
On Apr 5, 10:33=A0am, Peter Duniho <no.peted.s...@no.nwlink.spam.com>
wrote:
> Spondishy wrote:
> > This is a bit of a mix between asp.net and c#, but I thought I'd try
> > here first.
>
> > I have a number of objects (imagine products) in an IList that I want
> > to render in the UI. They all inherit from the same base class. The
> > individual classes have extra attributes, for example one might have
> > weight, another color.
>
> > I want a generic way to render these in the UI, without the need of a
> > huge switch statement. Should each object know how to render itself
> > for instance?
>
> > Any implemented examples around the net would be good. Thanks.
>
> The question is a classic example of where you should use some form of
> polymorphism.
>
> You can either define an interface that each object implements, or the
> base class can include a virtual method for rendering that each object
> overrides.
>
> A Google search can turn up a wealth of information on both, as far as
> examples go.
>
> Pete
Thanks Pete... I'm fine with polymorphism. Just to add some context. I
have a list of objects that I want to display on an asp.net page and
depending on the object, display differently. I've read some articles
on having a factory create the user controls, but it look messy.
|
|
0
|
|
|
|
Reply
|
Spondishy
|
4/6/2010 9:48:24 AM
|
|
Spondishy wrote:
> Thanks Pete... I'm fine with polymorphism. Just to add some context. I
> have a list of objects that I want to display on an asp.net page and
> depending on the object, display differently. I've read some articles
> on having a factory create the user controls, but it look messy.
I'm afraid there's not anything in your post that suggests a specific
question to answer. If you're having trouble with some ASP.NET-specific
aspect of the problem, I would agree that the ASP.NET newsgroup is a
better place to ask the question.
If you're having trouble with some C#-specific aspect of the problem,
perhaps you could elaborate on what, specifically, is the question you have?
Pete
|
|
0
|
|
|
|
Reply
|
Peter
|
4/6/2010 3:29:22 PM
|
|
|
3 Replies
205 Views
(page loaded in 0.039 seconds)
Similiar Articles: Filter Custom List on Date - microsoft.public.sharepoint.general ...Custom Filter based on system date for a List View? ... like to filter a sharepoint list view of tasks to only show items ... custom template for rendering a list filter: microsoft.public.sqlserver.reportingsvcsItems(542) /55 Next >> Last >| ... RS2008 to change the background color of a chart based ... SOAP Webservice Data Source (Input object type) Utf 0 529 ... microsoft.public.powerpoint - page 6How do I add a design I have to the design list to use ... Importing object with transparent backgrounds Utf 2 436 In PP ... video clip in powerpoint Utf 1 284 how do i cut and render a ... 1920x1080 how some programs (non-menu area) fonts are displayed ...WXP does react a little differently that the other two, and ... normal, but @ 113 dpi then all the other Menu items by ... in the moment anyway) and their marriages are based ... Parsing CSV files - microsoft.public.vc.mfc... Overall, I find that parsers that are based on ... Logically, many rendering programs will try \r as "reset ... change it, and our compiler assigned registers differently ... Value and Text Properties of controls - microsoft.public.access ...... had to create my own custom listbox class object to ... Providing unbound List based controls with Text and Value ... The Text property of the control is used differently by ... XML vs SQL Server - microsoft.public.dotnet.languages.csharp ...Items 1-3 (above) are true limitations of utilizing ... this is to make a check on the type of ADO.NET object ... if the new DBMS needs the query to be written differently. MFC under VS2010 - microsoft.public.vc.mfcThe HTML parsing and rendering engine, or the UI of the ... Or put it differently: something a single guy can put ... get the menu bar to show in my dialog and add items ... Determine the Sharepoint Library - microsoft.public.word.vba ...> > > > Is there a way, via the Word object model, to set the ... Maximum number of items in a list or library - microsoft.public ... ... that you can share with team members on a Web based ... Value Metadata - microsoft.public.excel.programmingHi How can I check (using VBA) if a cell has some metadata associated (as described here: http://msdn.microsoft.com/en-us/library/dd953161.aspx). episerver - Render a page differently based on which list that ...Render a page differently based on which list that opened it ... "get the list's PageData object by the HTTP ... of querystring to the PR items in the list ... How to: Create a Custom Field Type - Microsoft Corporation ...In the context of a list view, an SPField object ... Foundation, and it rendered differently on list views from the default rendering ... create a new column that is based ... Rendering An Unordered List Using C#? - Web Forms :: Disable All ...... data I need to render an unordered list based on ... controls in the list items? Do I need to approach the problem differently? ... the following to render the Points objects: ... Changing a List View Web Part to render a custom field differently ...... List View Web Part to render a custom field differently. ... object model broken All I want to do is manipulate list items (not ... list form based on the list ... How to: Create Field Rendering Templates - Microsoft Corporation ...A field rendering template is a RenderingTemplate object that is defined as a RenderingTemplate ... rendering templates and to switch between them based on the rendering ... 7/29/2012 9:38:44 AM
|