Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
How can I make dynamic multiple columns in repeater in asp.net c#.

please see below structure just for reference.
VB
|  year  |  year  |  year  |  year
name | amount | amount | amount | amount
name | amount | amount | amount | amount
name | amount | amount | amount | amount
name | amount | amount | amount | amount


in my case I might have 2 or 3 or 4 or any no. of products to be compared so I need to display multiple products with multiple features to be compared.

ref. site: http://www.biocompare.com/ProductCompare.aspx?i=2936820,79743,438523,0000[^]


thanks in advance.
Posted

1 solution

Have you taken a look at this?

ASP.Net Repeater dynamically using C# code[^]

[UPDATE]

You can actually pivot the datatable before binding it to the repeater.
Pivoting a DataTable[^]

After you made your pivot on the datatable, you can now create your repeater in your code behind. Refer to the first URL on how to do it.
 
Share this answer
 
v2
Comments
trilokharry 5-Apr-11 1:20am    
Hinot able to get sample in reference site what you have given me for dynamic columns.
my scenario is:
table can have 2 or 3 or 4 or 5 rows of products.
if no. of rows are 2 means columns will be 2.
if no. of rows are 3 means columns will be 3.

columns in table will be used to display features of product for comparison.

thanks for your kind response.
walterhevedeich 8-Apr-11 2:33am    
But thats exactly how you do it. If you are building a repeater with dynamic columns, you should do it in the code behind. As you can see the URL I provided, there are code snippets which demonstrates you how to do it.
trilokharry 8-Apr-11 2:10am    
thanks for kind response.

my scenario is:

suppose I have 4 records of products in DataTable.

4 rows in DataTable with p1, p2, p3, p4 with respective product features.

if 4 rows means I want to make 4 columns or if it is 2 row means 2 columns.

Particular Product features will be used to be compared.

How can I achieve same by repeater control in asp.net c#.



thanks
walterhevedeich 8-Apr-11 2:33am    
in your scenario, how many columns do you have in your DataTable?
trilokharry 8-Apr-11 2:48am    
in my scenario columns might be any no. of and will be treated as a feature in DataTable.
but columns in a repeater will be based on no. of rows in DataTable.

like:
result of this query:
select *from product where ProductId in(2,3,6,7);
4 products will be in result and will be compared.
min prod compare 2 and max will be 5 so max repeater column will be 5 and so max no. of rows also will be 5.

thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900