views:

340

answers:

3

I have a Data Table that is filled from a database connection. I would like to run checks on the Data Table like replacing the numbers with text and add my own data before binding it to the Data Grid for viewing. How do I access one piece of data in the Data Table? Thanks.

+2  A: 

Just look in the table's .Rows collection, and access fields in each row using normal array ( [] ) notation using either column index or field name for the subscript.

Joel Coehoorn
A: 

You can subscribe to the ItemDataBound event of the DataGrid, then modify the contents of the DataGridRow before it's all sent back to the browser.

Here's an example of its use. Inside the event handler, try:

Label lblBalance = (Label)e.Item.FindControl("dgLabel2");

or

e.Item.Cells[2].Text = "whatever text"
EndangeredMassa
A: 
DataSet ds = GetData();
foreach( DataTable dt in ds.Tables )
{
   foreach( DataRow row in dt.Rows )
   {
      if ( row["columnName"] != DBNull.Value )
      {
         row["columnName"] = "some data";
      }
   }
}
DataBind();
Muad'Dib