Thursday, February 4, 2010

C# - display content in table

Below is a simple example to display content in table:

{
// create table for display
DataTable table = new DataTable();
table.Columns.Add("TimeStamp", typeof(string));
table.Columns.Add("UserID", typeof(string));
table.Columns.Add("TID", typeof(string));

// loop to add records
while (...)
{
...
table.Rows.Add(strMess1, strMess2, strMess3);
...
}

// display content to GridView
// (Assume GridView has been defined in designer of Visual Studio)
dataGridView1.DataSource = table;
}

No comments: