Friday, February 1, 2013

Create gridview with variable number of columns

Create gridview with variable number of columns

I have to generate a gridview with the numbers of columns depending on a period of time then bind around 10 rows of data to the grid

Sometimes, I'll need to see every day in a year -> 365 columns

or every day in a month -> 30,31 columns

or every hour in a week -> 168 columns

or sometimes from the 15th of january to the 23 of march where I'll have to count the number of days.

My idea was to create as many object types as necessary to handle each possible case and I would call the correct type when asked.

However this seems cumbersome since creating an object with 365 properties then one with 168, etc... doesn't seems optimized.

How should I implement that ?

Answers & Comments...

Answer: 1

Generating the columns should be easy enough. Creating classes can be done dynamically at runtime using the ICustomTypeProvider interface.

Essentially, you can create a dynamic type with whatever properties you want. Unlike generating Types with IL, you can also dynamically add properties whenever you like.

by : TriggerPinhttp://stackoverflow.com/users/1549726




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog