简体   繁体   English

创建具有可变列数的gridview

[英]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 我必须根据一段时间来生成带有列数的gridview,然后将大约10行数据绑定到网格

Sometimes, I'll need to see every day in a year -> 365 columns 有时,我需要查看一年中的每一天-> 365列

or every day in a month -> 30,31 columns 或一个月中的每一天-> 30,31列

or every hour in a week -> 168 columns 或一周中的每个小时-> 168列

or sometimes from the 15th of january to the 23 of march where I'll have to count the number of days. 或从1月15日到3月23日,有时我需要计算天数。

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. 但是,这似乎很麻烦,因为创建具有365个属性的对象,然后创建具有168个属性的对象,等等...似乎没有进行优化。

How should I implement that ? 我应该如何实施呢?

Generating the columns should be easy enough. 生成列应该足够容易。 Creating classes can be done dynamically at runtime using the ICustomTypeProvider interface. 可以使用ICustomTypeProvider接口在运行时动态创建类。

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. 与使用IL生成类型不同,您还可以根据需要动态添加属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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