.aspx.cs代码:
private void Button1_Click(object sender, System.EventArgs e)
{
MyDataGrid.AllowPaging = false;
BindGrid();
DGToExcel.ToExcleFile(MyDataGrid) ;
MyDataGrid.AllowPaging = true;
BindGrid();
}
.cs类代码
public void ToExcleFile(DataGrid MyDataGrid)
{
MyDataGrid.SelectedItemStyle.BackColor = Color.White;
MyDataGrid.AlternatingItemStyle.BackColor = Color.White;
MyDataGrid.ItemStyle.BackColor = Color.White;
MyDataGrid.HeaderStyle.BackColor = Color.White;
MyDataGrid.HeaderStyle.ForeColor = Color.Red;
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Filel123.xls"); HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "";
MyDataGrid.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
MyDataGrid.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}可就是这两句出错,
HttpResponse resp;
resp = Page.Response;
提示:
c:\inetpub\wwwroot\DGToExcel2_Sample\WebDataAccess.cs(43): 非静态的字段、方法或属性“System.Web.UI.Page.Response”要求对象引用
在网上找了找,没能解决,请大家帮忙看看.
private void Button1_Click(object sender, System.EventArgs e)
{
MyDataGrid.AllowPaging = false;
BindGrid();
DGToExcel.ToExcleFile(MyDataGrid) ;
MyDataGrid.AllowPaging = true;
BindGrid();
}
.cs类代码
public void ToExcleFile(DataGrid MyDataGrid)
{
MyDataGrid.SelectedItemStyle.BackColor = Color.White;
MyDataGrid.AlternatingItemStyle.BackColor = Color.White;
MyDataGrid.ItemStyle.BackColor = Color.White;
MyDataGrid.HeaderStyle.BackColor = Color.White;
MyDataGrid.HeaderStyle.ForeColor = Color.Red;
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Filel123.xls"); HttpResponse resp;
resp = Page.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "";
MyDataGrid.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
MyDataGrid.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}可就是这两句出错,
HttpResponse resp;
resp = Page.Response;
提示:
c:\inetpub\wwwroot\DGToExcel2_Sample\WebDataAccess.cs(43): 非静态的字段、方法或属性“System.Web.UI.Page.Response”要求对象引用
在网上找了找,没能解决,请大家帮忙看看.
解决方案 »
- 用Dictionary怎样储存
- 连接数据库插入数据的问题。。。
- 避免频繁刷新来增加访问量
- asp.net弹窗后点击确定页面跳窗到另外一页
- !!!!!!!!!!!!!!!!!!!!关于日期格式问题!!!!!! string sj = DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss");
- asp.net下怎么了邮件,大家有没有好有方法!!!!
- 关于路径的简单问题,在线等
- b/s系统该如何加密,网卡绑定好像不奏效啊????????????
- asp.net 初学者
- 如何让dbgrid始终显示
- 站内的多表搜索如何做?
- 分不多了,请教!在DATAGRID中如何取得摸板列中的LABEL的值?
//resp = Page.Response;
resp = HttpContext.Current.Response;