user1882705
user1882705

Reputation: 1081

Table with dynamic number of columns to show

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

Upvotes: 0

Views: 1201

Answers (2)

Praveen Nambiar
Praveen Nambiar

Reputation: 4892

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();

Upvotes: 1

Related Questions