开发者

C# (ASP.NET) now datalist for each DB entry

I am workin开发者_如何转开发g on a website and I have some db table called "downloads" where I have files I want users to download. The files are bound to "download type" table. I know how to display the data from the db on the page, but how do I "split" it so that I have for eg.

download type 1

file 1

file 2

file 3

download type 2

file 1

file 2

file 3

download type 3

file 1

file 2

file 3

... I hope my question is reasonable... So, the "non-dynamic" way would be to make a datalist for each entry, but what if the user puts one more "donwload type" in the db..?

Any tips are welcome!

Thanks for your time!


You could use a repeater or a GridView to perform this task.

If you have access to LINQ:
Create a LINQ query to get all of the data into a sorted IQueryable object that is sorted by download type. You can then iterate through this list using a repeater or a gridview and each time you come to a new download type, you can output the bolded type before continuing with the next item of data.

If you're stuck using datatables
Get your data down into a datatable and make sure it's sorted by download type. Then you can use the DefaultView of the table to perform filters or with a repeater you can follow similar instructions to above.

Keep in mind, you'll have to use the onDataBound events of these items and keep track of the current downloadtype with a global variable.


This can be accomplished using a GridView with grouping. Unfortunately, the ASP.NET Gridview doesn't make this as easy as it should be. But here is an article about how to do this:

http://aspalliance.com/1268_CodeSnip_How_to_Group_Data_in_the_GridView_Control.all

You can use this technique to bind your data to a Gridview and then Group by the Download Type column.

There are 3rd party products which make this extremely easy, but they aren't always free. One that we use is DevExpress. With their GridView you just tell it which column(s) to group by and you're done. If this is something you need to do routinely or would like to allow you users to do, then it would be worth buying.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜