简体   繁体   中英

Display the selected record

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?

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM