一、将gridview的导出Excel的数据格式定义为文本格式
方式一:在导出事件中
string style = "<style> td { mso-number-format:\"\\@\"; } </style> ";//导入excel时,将所有数据类型改为文本类型
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
stringWrite.WriteLine(style);
方式二:在gridview的RowDataBound事件中
protected void gdvTerminalDetals_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[8].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}
二、异常“只能在执行Render()的过程中调用RegisterForEventValidation”的解决办法(转载:http://www.cnblogs.com/lhxhappy/archive/2008/05/27/1208553.html)
当出现下面的异常的时候:
只能在执行Render()的过程中调用RegisterForEventValidation
当出现的异常的提示:
异常详细信息: System.InvalidOperationException:只能在执行Render()的过程中调用RegisterForEventValidation;
解决办法:
出现这个异常,解决问题只需要在<%@ Page %> 指令中加上 EnableEventValidation="false"