将 c# 数据table 转换为 HTML... 如何在 HTML table 中的单元格周围添加网格?

Converted c# datatable to HTML... how to add grid around the cells in HTML table?

因此使用在此 link 上找到的答案:

Creating HTML from a DataTable using C#

我通过数据table成功转换为HTML,它在我的电子邮件中显示为table...

我知道必须有一个地方可以放置在单元格周围添加网格线的样式,但我一直找不到合适的位置。我已经成功地在整个 table 周围添加了边框,但是...

DataTable dt = new DataTable();
sdaGetValidation.Fill(dt);   

StringBuilder sb = new StringBuilder();
sb.AppendLine("<html>");
sb.AppendLine("\t" + "<body>");
sb.AppendLine("\t\t" + "<table>");
sb.Append("<table border='1px' solid line black cellpadding='5' cellspacing='0' ");
sb.Append("style='border: solid 1px Silver; font-size: x-small;'>");

sb.Append("\t\t" + "<tr>");

foreach (DataColumn dc in dt.Columns)
{
    sb.AppendFormat("<td>{0}</td>", dc.ColumnName);
}

sb.AppendLine("<tr>");

foreach (DataRow dr in dt.Rows)
{
    sb.Append("\t\t\t" + "<tr>");

    foreach (DataColumn dc in dt.Columns)
    {
        string cellValue = dr[dc] != null ? dr[dc].ToString() : "";
        sb.AppendFormat("<td>{0}</td>", cellValue);
    }

    sb.AppendLine("</tr>");
}

sb.AppendLine("\t\t\t" + "</table>");
sb.AppendLine("\t" + "</body>");
sb.AppendLine("</html>");

MessageBox.Show(sb.ToString());

我不确定是否有办法重述旧答案,所以如果有办法,我深表歉意...

不是一个 HTML 人所以我觉得对于比我更了解它的人来说这应该是一个轻松的胜利。

我在这一行添加了'solid line black':

 sb.Append("<table border='1px' solid line black cellpadding='5' cellspacing='0' ")

但是没有快乐....

只需在生成 table 单元格的位置添加内联样式。

sb.AppendFormat("<td style=\"border:solid 1px black\">{0}</td>", cellValue);