Table with dynamic number of columns to show

寵の児 提交于 2019-12-14 03:18:34

问题


I have a data table with data like "insurance name, plantype, premium...." for each row.

So on my front end I have to show like below:

Insurance Name     HealthNet       Harvard         UniCare

Plan Type            HMO            PPO              HMO  

Premium              100            150             200

So sometimes I may have only two columns to show HealthNet and Harvard. Sometimes more than three. How to use repeater in this case to make it dynamic based on data table count?

Thanks


回答1:


Sample:

aspx markup as shown below:

<asp:GridView ID="gv" runat="server" AutoGenerateColumns="true">
</asp:GridView>

In codebehind simply do this:

gv.DataSource = yourDataTable;   // doesn't matter how many columns are there, it will handle it automatically
gv.DataBind();



回答2:


This will help how to pivot a data table:

http://geekswithblogs.net/dotNETvinz/archive/2009/05/10/pivot-data-in-gridview---a-generic-pivot-method-with.aspx



来源:https://stackoverflow.com/questions/15621099/table-with-dynamic-number-of-columns-to-show

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!