Best Way to DataBind a List with sub-related content (For example, SO's questions with tags)

后端 未结 2 505
一个人的身影
一个人的身影 2021-01-27 04:12

Using ASP.net 2.0, how do I present the information to the user similar to the Questions list on SO where each question has some child items (like the tags).

I would pro

2条回答
  •  别那么骄傲
    2021-01-27 04:44

    If you do two separate queries, you can still make them in one call to the database, and get back two resultsets.

    Instead of DataSets, you could use the more efficient DataReader (with two resultsets). Loop through the resultsets and populate Question objects with associated Tag objects or properties. Put those objects in an ArrayList or a generic List, and you can bind it to your Repeater.

    Instead of doing anything in code-behind, you should consider moving that code to at least a data access layer (class) if you don't need a business logic layer (another class).

    All of these suggestions only apply if your app is non-trivial. Using OO methods does add to the code, but if you are doing anything beyond displaying the information, it would be better to start off with a good OO architecture (DAL and BLL, if not MVC).

提交回复
热议问题