I found a better and cleaner way to display the values from a disposable datatable called dt. This code should work as intended, create a table on the email body, by using the disposable table that's created to store the values.
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID"));
DataRow dr = dt.NewRow();
dr[0] = "ID -" + txtSomething.Text;
dt.Rows.Add(dr);
MailMessage mm = new MailMessage("your_email@something.com", "your_email@something.com");
StringBuilder sb = new StringBuilder();
sb.Append("<p><table width='100%' style='border:Solid 1px Black;'>"); for (int colIndx = 0; colIndx < dt.Columns.Count; colIndx++)
{
sb.Append("<th>");
sb.Append(dt.Columns[colIndx].ColumnName);
sb.Append("</th>");
}
sb.Append("</thead>");
for (int rowIndx = 0; rowIndx < dt.Rows.Count; rowIndx++)
{
sb.Append("<tr>"); for (int colIndx = 0; colIndx < dt.Columns.Count; colIndx++)
{
sb.Append("<td>");
sb.Append
(dt.Rows[rowIndx][colIndx].ToString());
sb.Append("</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
mm.Body = sb.ToString();
mm.IsBodyHtml = true;