TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhimanyu Singh
NA
116
48.9k
how to send grid row data after the multiple selection
Nov 28 2012 2:30 AM
I want to send a single mail after of multiple selection of check boxes from grid view data row.
I putted the following code :
protected void Button1_Click(object sender, EventArgs e)
{
// StringBuilder object
StringBuilder str = new StringBuilder();
// Select the checkboxes from the GridView control
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
//chkSelect.Checked = Convert.ToBoolean(Session["a"]);
if (isChecked)
{
// Column 2 is the Hoarding_ID column
str.Append(GridView1.Rows[i].Cells[0].Text);
}
}
// prints out the result
Response.Write(str.ToString());
string a = GridView1.SelectedRow.Cells[2].Text;
Session["a"] = a.ToString();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select email_id from Hoarding_buyers where username = '" + Session["b"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
con.Close();
if (Session["b"] != null)
{
System.Web.Mail.MailMessage objMM = new System.Web.Mail.MailMessage();
objMM.To = dt.Rows[0][0].ToString();
objMM.From = "
[email protected]
";
objMM.BodyFormat = System.Web.Mail.MailFormat.Text;
objMM.Priority = System.Web.Mail.MailPriority.High;
objMM.Subject = "HoardingIndia";
objMM.Body = "Dear Sir/Madam,\r\n\r\n" +
"Thank You for Contacting Us. \r\n" +
"Our Marketing Team will contact you soon.\r\n\r\n" +
"Thanks & regards \r\n" +
"Hoardingindia.co.in \r\n" +
"011-22239165, +91-8826225511 \r\n\r\n";
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp.gmail.com";
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 465;
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "hoardingindia2012";
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "hoardingindia2012";
objMM.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = true;
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
System.Web.Mail.SmtpMail.Send(objMM);
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from Hoarding_buyers where username = '" + Session["b"].ToString() + "'", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
DataTable dt1 = ds1.Tables[0];
con.Close();
con.Open();
SqlDataAdapter da2 = new SqlDataAdapter("select * from providers_post where h_id = '" + Session["a"].ToString() + "'", con);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
DataTable dt2 = ds2.Tables[0];
con.Close();
con.Open();
SqlDataAdapter da3 = new SqlDataAdapter("select * from providers where provider_user_name in (select Provider_user_name from providers_post where h_id = '" + Session["a"].ToString() + "')", con);
DataSet ds3 = new DataSet();
da3.Fill(ds3);
DataTable dt3 = ds3.Tables[0];
con.Close();
System.Web.Mail.MailMessage objMM1 = new System.Web.Mail.MailMessage();
objMM1.To = "
[email protected]
";
objMM1.From = "
[email protected]
";
objMM1.BodyFormat = System.Web.Mail.MailFormat.Text;
objMM1.Priority = System.Web.Mail.MailPriority.High;
objMM1.Subject = "HoardingIndia";
objMM1.Body = "Dear Sir/Madam,\r\n\r\n" +
"We have received the details from hoarding buyer. \r\n\r\n" +
"Name :" + dt1.Rows[0][1].ToString() + "\r\n" +
"Email :" + dt1.Rows[0][10].ToString() + "\r\n" +
"Contact No.:" + dt1.Rows[0][3].ToString() + "\r\n\r\n" +
"-----------------------------------------------------------------------" + "\r\n\r\n" +
"Following are the hoarding details. \r\n\r\n" +
"Hoarding ID:" + Session["a"].ToString() + "\r\n\r\n" +
"Address :" + dt2.Rows[0][1].ToString() + "\r\n" +
"LandMark :" + dt2.Rows[0][6].ToString() + "\r\n" +
"State :" + dt2.Rows[0][4].ToString() + "\r\n" +
"District :" + dt2.Rows[0][5].ToString() + "\r\n" +
"Pin Code :" + dt2.Rows[0][8].ToString() + "\r\n" +
"Size :" + dt2.Rows[0][3].ToString() + "\r\n" +
"From Date:" + dt2.Rows[0][9].ToString() + "\r\n" +
"To Date :" + dt2.Rows[0][14].ToString() + "\r\n\r\n" +
"Hoarding Type:" + dt2.Rows[0][11].ToString() + "\r\n" +
"Lighting Type :" + dt2.Rows[0][15].ToString() + "\r\n" +
"Hoarding Cost:" + dt2.Rows[0][7].ToString() + "\r\n\r\n" +
"-----------------------------------------------------------------------" + "\r\n\r\n" +
"Following are the Hoarding owner's details in which buyer is intereated: \r\n\r\n" +
"Name :" + dt3.Rows[0][1].ToString() + "\r\n" +
"Email Id :" + dt3.Rows[0][6].ToString() + "\r\n" +
"Contact No.: " + dt3.Rows[0][2].ToString() + "\r\n\r\n\r\n";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp.gmail.com";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 465;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "hoardingindia2012";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "hoardingindia2012";
objMM1.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = true;
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
System.Web.Mail.SmtpMail.Send(objMM1);
//Response.Write("<script>alert('Thank you,we will contact you soon.')</script>");
Response.Redirect("search.aspx");
}
}
but the above code is throwing following error please help me:
Exception Details:
System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 437: { Line 438:
Line 439: string a = GridView1.SelectedRow.Cells[2].ToString();
Line 440: Session["a"] = a.ToString(); Line 441:
earlier it was sending a mail by selecting single row data but now i putted the check boxes after this its not working
Reply
Answers (
13
)
can any one tell how to retrive data from xml and present it
How to sync my Facebook contacts on Window Phone Using C#