E
Eva
Unregistered / Unconfirmed
GUEST, unregistred user!
我的DataGrid是自动产生的(表头也是),而且有设置排序。
我导出到excel文件后打开文件内容是一段错误说明“类型“DataGridLinkButton”的控件“gridCustList__ctl2__ctl0”必须放在具有 runat=server 的窗体标记内。”为什么会出这个错?我以前也有用到这段导出的程序,是正确的。是不是因为有设置排序?那应该怎么解决?
导出到Excel我是这样写的:
public static void ExpToExcel(System.Web.UI.Page In_Page,DataGrid In_DataGrid,string Title)
{
HttpResponse Resp=In_Page.Response;
string strFileName=DateTime.Now.Year.ToString() + "-" +
DateTime.Now.Month.ToString() + "-" +
DateTime.Now.Day.ToString() +
".xls";
Resp.ContentEncoding = Encoding.GetEncoding("GB2312");
Resp.AppendHeader("Content-Disposition", "attachment;filename="+ strFileName);
In_DataGrid.BorderColor=Color.FromName("black");
In_DataGrid.HeaderStyle.BackColor=Color.FromName("lightgray");
In_DataGrid.HeaderStyle.ForeColor=Color.FromName("black");
In_DataGrid.FooterStyle.BackColor=Color.FromName("lightgray");
In_DataGrid.FooterStyle.ForeColor=Color.FromName("black");
System.IO.StringWriter objWriter=new System.IO.StringWriter();
HtmlTextWriter objHtmWriter=new HtmlTextWriter(objWriter);
In_DataGrid.RenderControl(objHtmWriter);
Resp.Write("<DIV Align=Center>"+Title+"</DIV>");
Resp.Write(objWriter.ToString());
Resp.End();
}
调用是这样:
private void ibtnExcel_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
ExpExcel.ExpToExcel(Page,gridCustList,"标题名称");
}
我导出到excel文件后打开文件内容是一段错误说明“类型“DataGridLinkButton”的控件“gridCustList__ctl2__ctl0”必须放在具有 runat=server 的窗体标记内。”为什么会出这个错?我以前也有用到这段导出的程序,是正确的。是不是因为有设置排序?那应该怎么解决?
导出到Excel我是这样写的:
public static void ExpToExcel(System.Web.UI.Page In_Page,DataGrid In_DataGrid,string Title)
{
HttpResponse Resp=In_Page.Response;
string strFileName=DateTime.Now.Year.ToString() + "-" +
DateTime.Now.Month.ToString() + "-" +
DateTime.Now.Day.ToString() +
".xls";
Resp.ContentEncoding = Encoding.GetEncoding("GB2312");
Resp.AppendHeader("Content-Disposition", "attachment;filename="+ strFileName);
In_DataGrid.BorderColor=Color.FromName("black");
In_DataGrid.HeaderStyle.BackColor=Color.FromName("lightgray");
In_DataGrid.HeaderStyle.ForeColor=Color.FromName("black");
In_DataGrid.FooterStyle.BackColor=Color.FromName("lightgray");
In_DataGrid.FooterStyle.ForeColor=Color.FromName("black");
System.IO.StringWriter objWriter=new System.IO.StringWriter();
HtmlTextWriter objHtmWriter=new HtmlTextWriter(objWriter);
In_DataGrid.RenderControl(objHtmWriter);
Resp.Write("<DIV Align=Center>"+Title+"</DIV>");
Resp.Write(objWriter.ToString());
Resp.End();
}
调用是这样:
private void ibtnExcel_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
ExpExcel.ExpToExcel(Page,gridCustList,"标题名称");
}