ASP.NET get cell from DataRow in a datatable? -


i wondering how access cells in datatable? thought like

  foreach (datarow siterow in sites.rows)         {             string sitename = siterow.cells[1].text;         } 

but doesn't seem work gridview. should do?

use indexer:

foreach (datarow siterow in sites.rows) {     string sitename = siterow[1].tostring(); // second column     // or via name:     sitename = siterow["sitename"].tostring; // if column name sitename     // or better via field method typed      // , supports nullable types:     sitename = siterow.field<string>(1); // works via name } 

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -