[已解决]在电子邮件中发送GridView唯一的特定列。 [英] [Solved] Sending GridView's only specific Columns in email.

查看:94
本文介绍了[已解决]在电子邮件中发送GridView唯一的特定列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web应用程序中有一个GridView。有9列。我只需要通过电子邮件发送6列的详细信息。这个问题的准确程序是什么?另外我将如何将这些列转换为HTML格式....请帮助。

I have a GridView in my web application. Having 9 Columns. I just need to send the detail of 6 columns from it through email. What will be the accurate procedure of this issue. Also how I will convert those column into HTML format.... Please Help.

推荐答案

您可以将gridview带入数据表,然后您可以删除n列使用dt.column.remove(columnname)之类的东西,然后你可以使用下面链接中给出的函数将你的数据表转换为htmltable,然后在你的电子邮件中发送这个html表..



http://samuellam.wordpress.com/2010/ 11/18 / render-datatable-as-html-table / [ ^ ]
You can take you gridview into datatable and then you can remove n number of columns using dt.column.remove(columnname) something like that and then you can convert your datatable to htmltable by using function given in below link and then send this html table in you email..

http://samuellam.wordpress.com/2010/11/18/render-datatable-as-html-table/[^]


第一步:将gridview转换为html表并删除不需要的列

私有字符串getHTML(GridView gv)

{



this.OrderGridView.AllowPaging = false;

T his.OrderGridView.AllowSorting = false;

this.OrderGridView.EditIndex = -1;



//让我们将数据绑定到GridView

this.RefreshGrid();

OrderGridView.Columns.RemoveAt(1);

OrderGridView.Columns.RemoveAt(0);

OrderGridView.DataBind();

//让我们输出GridView的HTML

StringBuilder sb = new StringBuilder();

StringWriter textwriter = new StringWriter(sb);

HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);

OrderGridView.RenderControl(htmlwriter);

htmlwriter。 Flush();

textwriter.Flush();

htmlwriter.Dispose();

textwriter.Dispose();

返回sb.ToString();

}



然后通过emai发送l:

First step: convert gridview to html table and remove the columns you don't want
private string getHTML(GridView gv)
{

this.OrderGridView.AllowPaging = false;
this.OrderGridView.AllowSorting = false;
this.OrderGridView.EditIndex = -1;

// Let's bind data to GridView
this.RefreshGrid();
OrderGridView.Columns.RemoveAt(1);
OrderGridView.Columns.RemoveAt(0);
OrderGridView.DataBind();
// Let's output HTML of GridView
StringBuilder sb = new StringBuilder();
StringWriter textwriter = new StringWriter(sb);
HtmlTextWriter htmlwriter = new HtmlTextWriter(textwriter);
OrderGridView.RenderControl(htmlwriter);
htmlwriter.Flush();
textwriter.Flush();
htmlwriter.Dispose();
textwriter.Dispose();
return sb.ToString();
}

Then send it via email:
protected void Button1_Click(object sender, ImageClickEventArgs e)
       {
          
           try
           {
string emailGR = getHTML(OrderGridView);

               System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
               System.Net.Mail.SmtpClient smptClient = new System.Net.Mail.SmtpClient("mail.*****.***");
               smptClient.Credentials = new System.Net.NetworkCredential("**@****.gr", "*****)d");

               mail.Body = "New Order From: " + "  " + username.Text + "<br/>" + "Total Amout:" + "  " + sum.Text + "<br/>" + "Notes:" + "  " + TextBox5.Text + emailGR;
               
               mail.IsBodyHtml = true;
               mail.To.Add(new System.Net.Mail.MailAddress("****@****.**"));
               mail.From = new MailAddress("customer@****.***");
               mail.Subject = "New Order From" + "   " + username.Text;
               smptClient.Send(mail);
               string Msg = "<script>alert('You have successfully sent your order!!');</script>";
               ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", Msg, false);
               //Response.Write(@"<script language='javascript'>alert('You have successfully sent your order!')</script>");
           }
           catch
           {
               string Msg = "<script>alert('Mail Sending Failed..try again!');</script>";
               ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", Msg, false);
               //Response.Write(@"<script language='javascript'>alert('Mail Sending Failed..try again!')</script>");
           }
           this.OrderGridView.AllowPaging = true;
           this.OrderGridView.AllowSorting = true;
           this.OrderGridView.EditIndex = -1;
           this.RefreshGrid();
           code.Focus();

       }


嗨...

见这个。可能对你有用。

Hi...
See this. May its useful to u.
//Reads values from ur gridview1.
GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
//assigning gridview1 controls to strings like blow.
string username = ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lblusername")).Text;
string fathername = ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lblfathername")).Text;
string address= ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lbladdress")).Text;
string zipcode= ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lblzipcode")).Text;
string mailid= ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lblmailid")).Text;
string phoneno= ((Label)GridView1.Rows[gvRow.RowIndex].FindControl("lblphoneno")).Text;



类似于从你的GridViewRow1中读取值。价值通过邮件。

谢谢你。


like that reads the values from ur GridViewRow1.After that sends that values through mail.
Thank u.


这篇关于[已解决]在电子邮件中发送GridView唯一的特定列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆