.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Images and Details through Email to that user

Posted By: kavitha     Posted Date: December 01, 2010    Points:2   Category :ASP.Net
hi friends,

All Images and Details from database are displayed in gridview / datalist.

I need,

if i click that particular row (send button in gridview / datalist) the Images and Details through Email to that particular user.(email Id is retreived from database).


create table reg(Date DateTime,rid varchar(200),NAME varchar(200),Email varchar(200),imgData image,imgType varchar(200),imgLength bigint,sid numeric identity)

please give in detail.

thanks in advance.

Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   


Author: krishana singh             
Posted Date: December 07, 2010     Points: 5   

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<asp:TemplateField HeaderText="Date">
<asp:Label ID="LblDate" runat="server" Text='<%#Eval("date") %>'></asp:Label>
<asp:TemplateField HeaderText="rid">
<asp:Label ID="LblRid" runat="server" Text='<%#Eval("rid") %>'></asp:Label>
<asp:TemplateField HeaderText="name">
<asp:Label ID="LblName" runat="server" Text='<%#Eval("name") %>'></asp:Label>
<asp:TemplateField HeaderText="E-Mail">
<asp:Label ID="LblEmail" runat="server" Text='<%#Eval("email") %>'></asp:Label>
<asp:TemplateField HeaderText="Send Mail">
<asp:Button ID="BtnSendMail" runat="server" Text="Click"
onclick="BtnSendMail_Click" />

code behind.

SqlConnection con;
DataSet ds;
SqlDataAdapter sqlda;

protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ToString());
ds = new DataSet();
sqlda = new SqlDataAdapter("SELECT * FROM reg", con);
sqlda.Fill(ds, "reg");
GridView1.DataSource = ds;

protected void BtnSendMail_Click(object sender, EventArgs e)
Button cb = sender as Button;
GridViewRow grow = (GridViewRow)cb.NamingContainer;
string date = ((Label)grow.FindControl("LblDate")).Text;
string rid = ((Label)grow.FindControl("LblRid")).Text;
string name = ((Label)grow.FindControl("LblName")).Text;
string email = ((Label)grow.FindControl("LblEmail")).Text;

string body = "Date: " + date + "<br /><br />rid: " + rid + "<br /><br />Name: " + name + "<br />Add other contents>";
string subject = "Automated Mail";
string result = SendMail("YourName", subject, body, email);

public string SendMail(string DisplayName, string Subject, string Body, string To)
int ClientPort;
string SenderEmailId, SenderPassword, SenderSmtpAddress;
// Adding Sender Information
ClientPort = 25;
SenderSmtpAddress = "smtp.domain.com"; // Change the domain name
SenderEmailId = "youremailid@domain.com"; // Change the Sender Email ID
SenderPassword = "yourpassword"; // Change the Sender Password

// Building the Message
MailMessage msg = new MailMessage();
msg.From = new MailAddress(SenderEmailId, DisplayName, System.Text.Encoding.UTF8);
msg.Subject = Subject;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = Body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;

// Adding the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(SenderEmailId, SenderPassword);
client.Port = ClientPort; //25 or use 587 or 465
client.Host = SenderSmtpAddress;
client.EnableSsl = true;
catch (SmtpException ex)
return ("Error: " + ex.Message);
return "Mail Sent Successfully";

Author: kavitha             
Posted Date: December 07, 2010     Points: 5   

thanks for your response,

but, also send details with Image(user Image) from database(not from the Image folder).

how to create it.

please give in detail.


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend