views:

67

answers:

3

I have a page that display of all News in a database, which I get with function

IList<News> GetAll();

I then bind the list to a repeater to display all the news. If a user clicks on news N, he is redirected to page.aspx?id=N

If the QueryString["id"] is set, then I get one of my News like this:

News news = sNewsService.Get(int.Parse(id));

Now, I would like to display this single news, but I cannot bind it to a Repeater as it does not implement IListSource or IEnumerable.

Is there any other way to display the properties of one news instead of writing every property value to a different Label like lText = news.Text; lTitle = news.Title;... or wrapping the news in a List?

+1  A: 

The DetailsView control is designed to display a single record. Not sure if that might help.

Andy White
The DetailsView control can be bound to a data source that implements the System.Collections.IEnumerable interface, so this will not work by itself.
Spikolynn
You could try to wrap your object in an ObjectDataSource
Andy White
+1  A: 

This appears to be a typical Master-Details scenario where your Repeater displays a List of News objects and then allows you to redirect to a Details page which will display additional detail about the selected News object.

In this case, I would suggest a FormView instead of a DetailsView which will allow you greater control over the details display since it requires user defined templates instead of preconfigured Row based display.

Since your News class does not implement IEnumerable, it is necessary that you use an ObjectDataSource to enable databinding. This datasource will be able to wrap your class and allow the FormView to bind to it using Eval based lookup syntax.

Cerebrus
A: 

I converted the product to MVC and created custom DTO's/Views

Spikolynn