How to get gridview Cells values based on column

Posted by Self-Innovator under C# on 11/30/2012 | Points: 10 | Views : 1885 | Status : [Member] | Replies : 1
Hi,
I have a problem in fetching the cells value from gridview while sending an email.
Please go through my error and code snippet and find me the proper solution to solve this.

Method to Send an Email

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[i].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;
}
protected void btnAddtoList_Click(object sender, EventArgs e)
{
ListItem li = new ListItem(txtCustomerID.Text);
if (!lstUsers.Items.Contains(li))
{
lstUsers.Items.Add(li);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Customer Id already exists');", true);
}
txtCustomer

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

<html><body><center><table border='1' cellpadding='0' cellspacing='0'>
<tr>
<td align='center' valign='middle'>Address</td>
<td align='center' valign='middle'>Date Of Birth</td>
<td align='center' valign='middle'>Phone</td>
<td align='center' valign='middle'>Education</td>
<td align='center' valign='middle'>Company Name</td>
<td align='center' valign='middle'>City</td>
<td align='center' valign='middle'>State</td>
<tr>
<tr>
<td align='center' valign='middle'>Address</td>
<td align='center' valign='middle'>Date Of Birth</td>
<td align='center' valign='middle'>Phone</td>
<td align='center' valign='middle'>Education</td>
<td align='center' valign='middle'>Company Name</td>
<td align='center' valign='middle'>City</td>
<td align='center' valign='middle'>State</td>
</tr>
</table></center></body></html>

Actual Grid View is Below

Address DOB Phone Qualification Company City State
no-5 tamil nadu 1/1/9180 080-2223456788 B.E nfosys Mumbai Maharashtra


Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Kundnani.Rt on: 1/19/2013 [Member] Starter | Points: 25

Login to post response