How to solve this anyone find solution

Posted by Self-Innovator under C# on 11/30/2012 | Points: 10 | Views : 772 | Status : [Member] | Replies : 1
Hi,
I need to send gridview data as an email where i am able to bind the gridview header values but i'm facing the problem on binding the content of gridview.Please go through the below code and find me the solution.
private StringBuilder htmlMessageBody(GridView dg)

{

StringBuilder strB = new StringBuilder();

strB.AppendLine("&lt;html>&lt;body><center><" +

"table border='1' cellpadding='0' cellspacing='0'>");

strB.AppendLine("<tr>");

for (int i = 0; i < dg.Columns.Count; i++)

{

strB.AppendLine("<td align='center' valign='middle'>" +

dg.Columns.HeaderText + "</td>");

}

strB.AppendLine("<tr>");

for (int i = 0; i < dg.Rows.Count; i++)

{

strB.AppendLine("<tr>");

for (int j = 0; j < dg.Columns.Count; j++)

{

strB.AppendLine("<td align='center' valign='middle'>" +

dg.Columns[j].ToString()+ "</td>");

}

strB.AppendLine("</tr>");

}

strB.AppendLine("</table></center>&lt;/body>&lt;/html>");

return strB;

}

My Mailing class file
here i'm calling the htmlMessageBodyfunction where i'm passing my gridview as a body of mail message
ml.mymail(allMails,htmlMessageBody(grdContctDetails).ToString() ,"Hello");


Here i'm getting an Email like this
Address DOB Phone Qualification Company City State
Instead of
Address DOB Phone Qualification Company City State
no-5 tamil nadu 1/1/9180 080-2223456788 B.E nfosys Mumbai Maharashtra

here i'm unable to get these values no5-tamilnadu,11/9180....

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Sheonarayan on: 11/30/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
In the loop, instead of writing

dg.Columns[j].ToString();


you need to probably write

dg.Rows[ii].Columns[j].ToString(); // write single i 


As you want to get the values of each column of each rows.

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Login to post response