hi , iam using asp.net with c#
iam sending gridview data in a mail ,but when gridview having many records in pages then, only first page is send in email and other pages are not send , can you correct my code how to send all data in a mail
Bash Copy
public override void VerifyRenderingInServerForm(Control control)
{
}
private string GridViewToHtml(GridView gv)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
gv.RenderControl(hw);
return sb.ToString();
}
protected void Button3_Click(object sender, EventArgs e)
{
//checkout
if (txtgrandtotal.Text == "" )
{
//click on total button
clsdataset.ShowAlertMessage("click on total" );
}
else
{
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["InventoryConnectionString" ].ConnectionString);
string note = TextBox2.Text;
Session["note" ] = note.ToString();
CheckBox cc; Label id ; Label categorynamee; Label itemkey; Label itemkeynamee; Label currentqty; Label salesprice;
Label quantity; Label total;
foreach (GridViewRow rr in GridView1.Rows)
{
cc = (CheckBox)rr.FindControl("chk" );
id = (Label)rr.FindControl("Label2" );
categorynamee = (Label)rr.FindControl("Label3" );
itemkey = (Label)rr.FindControl("Label4" );
itemkeynamee = (Label)rr.FindControl("Label5" );
currentqty = (Label)rr.FindControl("Label6" );
salesprice = (Label)rr.FindControl("Label7" );
quantity = (Label)rr.FindControl("Label8" );
total = (Label)rr.FindControl("Label1" );
Session["Orderno" ] = id.Text;
if (cc.Checked == true && cc.Visible == true )
{
//update tblorder
//SqlCommand cmdupd = new SqlCommand("addnotesproc" , con1);
//con1.Open();
//cmdupd.CommandType = CommandType.StoredProcedure;
//cmdupd.Parameters.AddWithValue("@OrderNo" , Convert.ToInt32(id.Text));
//cmdupd.Parameters.AddWithValue("@Note" , TextBox2.Text);
//cmdupd.ExecuteNonQuery();
//con1.Close();
//insert TblDetails
SqlCommand cmptbldetails = new SqlCommand("Addorderdetails" , con1);
cmptbldetails.CommandType = CommandType.StoredProcedure;
con1.Open();
cmptbldetails.Parameters.AddWithValue("@OrderNo" ,Convert.ToInt32(id.Text));
cmptbldetails.Parameters.AddWithValue("@CategoryNameE" ,categorynamee.Text);
cmptbldetails.Parameters.AddWithValue("@ItemKey" ,itemkey.Text);
cmptbldetails.Parameters.AddWithValue("@ItemKeyNameE" ,itemkeynamee.Text);
cmptbldetails.Parameters.AddWithValue("@CurrentQTY" ,currentqty.Text);
cmptbldetails.Parameters.AddWithValue("@SalesPrice" ,salesprice.Text);
cmptbldetails.Parameters.AddWithValue("@Quantity" ,quantity.Text);
cmptbldetails.Parameters.AddWithValue("@Total" ,total.Text);
cmptbldetails.Parameters.AddWithValue("@time1" , DateTime.Now.ToString());
cmptbldetails.Parameters.AddWithValue("@Notes" , TextBox2.Text);
cmptbldetails.ExecuteNonQuery();
con1.Close();
}
}
//updating tblorder
//upto here
System.Net.Mail.SmtpClient smtp = new SmtpClient();
System.Net.Mail.MailMessage msg = new MailMessage();
MailAddress fromaddress = new MailAddress("[email protected] " );
msg.From = fromaddress;
string mailto = Session["Areamanager" ].ToString();
msg.To.Add(mailto);
msg.Subject = "your Purchase Details" ;
msg.Body = "ShopId::" + Session["UserName" ].ToString() + "
" + "ShopName::" + Session["sendershopname" ].ToString() + "
" + "OrderNo::" + Session["Orderno" ].ToString() + "
" + "OrderDate::" + DateTime.Now.ToString() + "
" + "Total::" + Session["total" ].ToString() + "
" + Session["note" ].ToString() + "." + "
" + GridViewToHtml(GridView1);
msg.IsBodyHtml = true ;
smtp.Host = "localHost" ;
smtp.Port = 25;
smtp.UseDefaultCredentials = true ;
smtp.Send(msg);
Response.Redirect("mailsend.aspx" );
}
}
PJ MartinsRank #2,548 · 548 reputationPosted Jun 5, 2010, 5:43 AM EDT