日期格式化
<asp:BoundField HeaderText="签订日" DataField="contractDate" DataFormatString="{0:yyyy-MM-dd}" />
<%# Eval("contractDate","{0:yyyy-MM-dd}")%>
数字格式化
<asp:BoundField HeaderText="数量" DataField="Quantity" DataFormatString="{0:G0}"/>
<%# Eval("Quantity","{0:G0}")%>
导出EXCEL
protected void btnExport_Click(object sender, ImageClickEventArgs e)
{
DataTable dt = DBHelper.GetTable("select * from EnterStockView order by EnterStockID desc");
gvwExport.DataSource = dt;
gvwExport.DataBind();
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment;filename=MyExcelFile.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvwExport.RenderControl(htw);
Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>");
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{ }