views:

742

answers:

3

I am working on an ASP.NET 1.1 project where the requirement is to create a matrix table where the number of rows and the number of columns are determined by two separate datasets and can vary. Once the matrix is created the page has several buttons that do postbacks that need the data and any modifications made to a cell in the matrix table to be retained.
The <asp:DataGrid />is the obvious option but how do I add columns dynamically to the control? I am also considering dynamically building <asp:table /> control on the fly but I am not really sure if this is the way to go.

A problem I have with datagrids is that they blindly bind to a dataset. The table I am creating has the first column as the sum and the second one as the weighted average of the subsequent column data. There is also a grouping of the columns.

In this scenario is it better to use a table server control and build the entire thing or do this in a datagrid ?

A: 

Not sure what is the bottleneck. It is possible to retain values in dataset using viewstate or session.

NinethSense
I have updated the question to clarify it better - I am more interested in whether dynamically adding columns to a datagrid is easier or building a asp:table server control.
Nikhil
A: 

You can create a instance of a column and what you need and add to data grid.Check google for samples instead of posting here,on google you would find sample of how to work with a data grid.Data grid is better.

abmv
The idea of this website (as I understand it) is to consolidate the answers to a question so people can come back to one source rather than have go through everything in google.
Nikhil
But its your responsibly as an employee and developer to keep your selfupdated regarding concepts expressed in the question.Anyway....
abmv
+2  A: 

you can programatically add columns to a datagrid like that :

BoundColumn linkColumn = new BoundColumn();
linkColumn.DataField = "UserID";
linkColumn.DataFormatString = "<a href='UserDetails.aspx={0}'>User Details</a>";
linkColumn.HeaderText = "User Details";

DataGrid1.Columns.Add(linkColumn);

programmatically adding rows is adding rows to datasource that you bind to datagrid, isn't it ?

In my opinion using grid is simpler, grid manages binding and formatting for you. But using table gives you ability to manage cells to you.

Canavar