protected string getTableHeaders()
{
string retVal = "";
int TotalColumns = GridView1.Columns.Count;
int col = 0;
for (col = 0; col < TotalColumns; col++)
{
retVal += GridView1.Columns[col].HeaderText;
if ((col + 1) < TotalColumns) retVal += ", ";
}
return retVal;
}
Here is how to iterate over the GridView cells to extract row and column data into a string. The cells can be custom delimited. Notice how this does not include Column.HeaderText :
protected string getDataCells()
{
string retVal = "";
int TotalColumns = GridView1.Columns.Count;
int TotalRows = GridView1.Rows.Count;
int col = 0;
int row = 0;
if (TotalColumns > 0 && TotalRows > 0)
{
for (row =0; row<TotalRows; row++)
{
for (col = 0; col < TotalColumns; col++)
{ // uses arbitrary ',' between column cells
retVal += GridView1.Rows[row].Cells[col].Text;
if ((col + 1) < TotalColumns) retVal += ", ";
}
// uses arbitrary ';' for end of row
retVal += ";";
}
}
return retVal;
}
4 comments:
What entertaining question
Hi,
I begin on internet with a directory
top [url=http://www.c-online-casino.co.uk/]online casino[/url] hinder the latest [url=http://www.casinolasvegass.com/]casinolasvegass.com[/url] free no set aside reward at the leading [url=http://www.baywatchcasino.com/]casino online
[/url].
Iterating GridView cells in C#.NET
Post a Comment