0
我目前使用字符串生成器和各種循環來將一些HTML解析爲webBrowser控件。但我怎麼能具體每個專欄和價值從我的dataGridView1
,以便我可以包裝HTML周圍。我有一個列dataGridView1中的行值,這是一個圖像的URL。如何使用c爲每個dataGridView行項目指定HTML#
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;
}
您的代碼錯位了一些
簡單來說,我如何顯示我的dataGridView的一行 – PriceCheaperton
我剛剛編輯/更新我的評論。如果問題與行相關,那麼它就像是與
回答
我認爲這必須是
你開始forlooping多個表格行之前關閉該行標籤。
如果你在你的return語句中放置一個斷點,你可以將StrB的內容複製到一個HTML編輯器中,該編輯器應該突出你的錯誤。
來源
2014-01-12 21:25:21 JMG
相關問題