Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (12.7k points)

 have a job that passes a collection into the body of an email. I want to highlight the first column. Currently, my code is converting the first row. How can I change this?

System.Text.StringBuilder sb = new System.Text.StringBuilder);

if(InData.Rows.Count > 0)

{

sb.Append("Hi There,<br><br>");

sb.Append("Please find the below mentioned Information. <br><br>");

sb.Append("<table style='border:1px solid black; border-collapse: collapse;'>");

sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

foreach (System.Data.DataColumn dc in InData.Columns)

{

   sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

   sb.Append(dc.ColumnName);

   sb.Append("</th>");

}

sb.Append("</tr>");

int rowNumber = 1;

foreach (System.Data.DataRow dr in InData.Rows)

{

    if (rowNumber == 1)

    {

   sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px; background-color:yellow;'>");

    }

    else

    {

        sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

    }

  foreach (System.Data.DataColumn dc in InData.Columns)

   {

      sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

      sb.Append(dr[dc.ColumnName].ToString());

      sb.Append("</td>");

   }

   sb.Append("</tr>");

   rowNumber ++;

}

sb.Append("</table><br><br>");

sb.Append("Regards,<br>");

sb.Append("Team QueryBot");

}

outEmailHtmlTable = sb.ToString();

1 Answer

0 votes
by (29.5k points)
edited by

The background color is highlighted for the row. In the below code I had removed background-color:yellow; for the row and added it for the column which will highlighted for the first column of each row.

System.Text.StringBuilder sb = new System.Text.StringBuilder;
if(InData.Rows.Count > 0)
{
sb.Append("Hi There,<br><br>");
sb.Append("Please find the below mentioned Information. <br><br>");
sb.Append("<table style='border:1px solid black; border-collapse: collapse;'>");

sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
foreach (System.Data.DataColumn dc in InData.Columns)
{
   sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
   sb.Append(dc.ColumnName);
   sb.Append("</th>");
}
sb.Append("</tr>");

int rowNumber = 1;
foreach (System.Data.DataRow dr in InData.Rows)
{

   sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

int colNumber=1;

  foreach (System.Data.DataColumn dc in InData.Columns)
   {

if(colNumber==1)
{
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;background-color:yellow;'>");
}
else
{
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

}
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
          sb.Append(dr[dc.ColumnName].ToString());
          sb.Append("</td>");
colNumber++;
       }
       sb.Append("</tr>");
       rowNumber ++;
    }
    sb.Append("</table><br><br>");
    sb.Append("Regards,<br>");
    sb.Append("Team QueryBot");
    }
    outEmailHtmlTable = sb.ToString();

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...