views:

242

answers:

2

Hello everyone,

I am using ADO.Net + C# + VSTS 2008 + SQL Server 2005. I bind an ADO.Net DataTable to a real database table, and then bind the DataTable to a grid view on ASP.Net page. My question is, if I want to do some data manipulation work (very simple, like add some prefix to some character data type rows, multiple integer data type rows by 100 or something) and display in grid view the manipulated data on page. What is the suggested best practices solution to do data manipulation? I cannot change the data inside database.

thanks in advance, George

+1  A: 

ADO.NET DataSets allow for "computed" columns. Have a look at the MSDN page on DataColumn.Expression for a rundown of the sorts of supported expressions.

If you're in the visual DataSet designer, just right-click on your table and add a column, then fill in the expression in the Properties box. Otherwise it's pretty straight forward to create a new DataColumn in code, set its Expression property, and add it to your DataTable.

Matt Hamilton
Cool! Question answered.
George2
A: 

Get the DataTable into a DataView, perform your edits and bind the DataView to the DataGrid

DataView dv = new DataView();

            dv.Table = dt; //where dt is the datatable
            dv.AllowDelete = true;
            dv.AllowEdit = true;
            dv.AllowNew = true;

to bind use : dv.ToTable() and not dv.Table[0]

Rashmi Pandit