如何創建新的gridview/datalist
並在代碼後填充併發送爲email body
? 我已經有一個DataList
填充項目,但我不想發送它的所有列。所以,我想用我想要的列生成一個gridview用於發送電子郵件。 下面是我已經這樣做了如何創建新的GridView並在代碼後面填充並作爲電子郵件正文發送?
GridView gv = new GridView();
DataTable tbl = new DataTable();
tbl.Columns.Add("Items", typeof(string));
tbl.Columns.Add("Price", typeof(string));
tbl.Columns.Add("Total", typeof(string));
List<HiredList> hl = new List<HiredList>();
hl = (List<HiredList>)Session["Hired"];
foreach (var i in hl)
{
DataRow itms = tbl.NewRow();
itms["Items"] = i.pName;
itms["Price"] = i.price;
itms["Total"] = i.pTotal;
}
//use AutoGenerateColumnsto let grid generate the column itself'
gv.AutoGenerateColumns = true;
gv.DataSource = tbl;
gv.DataBind();
那麼這個GridView控件發送到
private string GetGridviewData(GridView gvList)
{
StringBuilder strBuilder = new StringBuilder();
StringWriter strWriter = new StringWriter(strBuilder);
HtmlTextWriter htw = new HtmlTextWriter(strWriter);
gvList.RenderControl(htw);
return strBuilder.ToString();
}
但作爲回報我只得到,在我收到的電子郵件。 我不知道我犯了什麼錯誤。
到目前爲止,您是否嘗試過任何方法?請閱讀[常見問題]和[問] – 2013-04-30 06:09:00