C# 在行下方动态添加行
我写这段代码是为了在gridview中进行更改时发送电子邮件 我以行格式发送一封包含列中所做更改的电子邮件。我需要在每行下方添加一行,我正在使用此代码,但它不起作用 我用这个部分在行C# 在行下方动态添加行,c#,asp.net,.net,C#,Asp.net,.net,我写这段代码是为了在gridview中进行更改时发送电子邮件 我以行格式发送一封包含列中所做更改的电子邮件。我需要在每行下方添加一行,我正在使用此代码,但它不起作用 我用这个部分在行sbMsg.AppendFormat(“”)下面添加了一行 公共字符串邮件格式(字符串代码) { List lstSpecificColumns=新列表(); DataTable dtCurrentTbl=activeApplication.LoadMailActiveApplications(Code.ToStri
sbMsg.AppendFormat(“”)下面添加了一行代码>
公共字符串邮件格式(字符串代码)
{
List lstSpecificColumns=新列表();
DataTable dtCurrentTbl=activeApplication.LoadMailActiveApplications(Code.ToString().Trim());
DataTable dtOldTbl=activeApplication.LoadMailLogManualUpdatesDetails(代码.ToString().Trim());
对于(int colIndex=0;colIndex”);
sbMsg.AppendFormat(“”);
sbMsg.AppendFormat(“+Code.ToString().Trim()+”);
foreach(resultTbl.Columns中的数据列dc)
{
sbMsg.AppendFormat(“”);
sbMsg.AppendFormat(“+dc.ColumnName.Trim()+”);
sbMsg.AppendFormat(“+resultTbl.Rows[1][dc].ToString().Trim()+”+“+resultTbl.Rows[0][dc].ToString().Trim()+”);
sbMsg.AppendFormat(“”);
}
sbMsg.AppendFormat(“”);
返回sbMsg.ToString();
}
有人能帮我吗。请注意,使用字符串生成器并在那里传递连接的字符串不是最好的主意-AppendFormat(“好的,那么我该如何实现这一点呢?类似的东西。AppendFormat(“文本{0}”,行)那个么到底是什么不起作用呢?你们有并没有得到任何错误或错误的结果?我并没有得到任何错误,但无法在行下面添加行。
public string mailFormatting(string Code)
{
List<string> lstSpecificColumns = new List<string>();
DataTable dtCurrentTbl = activeApplication.LoadMailActiveApplications(Code.ToString().Trim());
DataTable dtOldTbl = activeApplication.LoadMailLogManualUpdatesDetails(Code.ToString().Trim());
for (int colIndex = 0; colIndex < dtCurrentTbl.Columns.Count; colIndex++)
{
if (!dtCurrentTbl.Rows[0][colIndex].ToString().Equals(dtOldTbl.Rows[0][colIndex].ToString()))
{
lstSpecificColumns.Add(dtCurrentTbl.Columns[colIndex].ColumnName);
}
}
dtCurrentTbl.Merge(dtOldTbl);
DataTable resultTbl = dtCurrentTbl.AsEnumerable().CopyToDataTable().DefaultView.ToTable(true, lstSpecificColumns.ToArray());
string rows = "\"rows\"";
StringBuilder sbMsg = new StringBuilder();
sbMsg.AppendFormat("<p><font color=gray>Title<font></p>");
sbMsg.AppendFormat("<table rules= + rows + style='font-family:Calibri;background-color:#F1F1F1' width='1000'>");
sbMsg.AppendFormat("<tr> <td colspan='2'> <font color=blue> <u> " + Code.ToString().Trim() + " </u></font><td></tr>");
foreach (DataColumn dc in resultTbl.Columns)
{
sbMsg.AppendFormat("<tr>");
sbMsg.AppendFormat("<td> " + dc.ColumnName.Trim() + " </td>");
sbMsg.AppendFormat("<td> <strike>" + resultTbl.Rows[1][dc].ToString().Trim() + "</strike>" + " " + resultTbl.Rows[0][dc].ToString().Trim() + " </td>");
sbMsg.AppendFormat("</tr>");
}
sbMsg.AppendFormat("</table>");
return sbMsg.ToString();
}