I currently use a string builder and various loops to parse some HTML to a webBrowser control. But how can i specific each column and value from my dataGridView1
so that i can wrap HTML around. I have a column with a row value in my dataGridView1 which is an image URL.
private StringBuilder htmlMessageBody(DataGridView dataGridView2)
{
StringBuilder strB = new StringBuilder();
//create html & table
strB.AppendLine("<html><body><center><" +
"table border='1' cellpadding='0' cellspacing='0'>");
strB.AppendLine("<tr>");
//cteate table header
for (int i = 0; i < dataGridView2.Columns.Count; i++)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dataGridView2.Columns[i].HeaderText + "</td>");
}
//create table body
strB.AppendLine("<tr>");
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
strB.AppendLine("<tr>");
foreach (DataGridViewCell dgvc in dataGridView2.Rows[i].Cells)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dgvc.Value.ToString() + "</td>");
}
strB.AppendLine("</tr>");
}
//table footer & end of html file
strB.AppendLine("</table></center></body></html>");
return strB;
}
//create table body
strB.AppendLine("<tr>");
I think this needs to be
//create table body
strB.AppendLine("</tr>");
to close the row tag before you start forlooping more table rows.
If you put a breakpoint on your return statement you can copy the contents of StrB into a html editor which should highlight your errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.