How to send contents of Datagridview through email

Posted by Self-Innovator under C# on 11/29/2012 | Points: 10 | Views : 2647 | Status : [Member] | Replies : 2
How to send contents of Datagridview through email in asp.net pls find me the soln....

I've tried but this is not working

 private StringBuilder htmlMessageBody(DataGridView dg)
{
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 < dg.Columns.Count; i++)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dg.Columns[i].HeaderText + "</td>");
}
//create table body
strB.AppendLine("<tr>");
for (int i = 0; i < dg.Rows.Count; i++)
{
strB.AppendLine("<tr>");
foreach (DataGridViewCell dgvc in dg.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;
}



Mail class
 ml.mymail(allMails,htmlMessageBody(grdContctDetails).ToString(),"Hello");


Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: aswinialuri-19361 on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
you will go through this code .I think It is very help full to you

http://www.codeproject.com/Articles/23640/How-to-send-DataGridView-contents-by-email

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 11/29/2012 [Member] Bronze | Points: 25

Up
0
Down
hi u've tried this same code but when i try calling from my class method the arguments throws an error
Have a look in my above code
Error line:
ml.mymail(allMails,htmlMessageBody(grdContctDetails).ToString(),"Hello");

Error Message:
Argument '1': cannot convert from 'System.Web.UI.WebControls.GridView' to 'System.Windows.Forms.DataGridView'



Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response