如题,程序在dgExcel.RenderControl(hw)出错:类型“GridView”的控件“dgExcel”必须放在具有 runat=server 的窗体标记内。代码如下:
protected void Page_Load(object sender, EventArgs e)
{
String strsql;
DataSet objDataset = new DataSet();
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["GoodsConnectionString"].ToString();
strsql = "select * from products";
SqlDataAdapter objAdapter = new SqlDataAdapter();
con.Open();
objAdapter.SelectCommand = new SqlCommand(strsql, con);
objAdapter.Fill(objDataset); //dgExcel是Gridview的id
DataView oView = new DataView(objDataset.Tables[0]);
dgExcel.DataSource = oView;
dgExcel.DataBind();
con.Close();
con.Dispose();
con = null;
if (Request.QueryString["bExcel"] == "1")//另一页面穿的值
{
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
dgExcel.RenderControl(hw);//程序在此出错
Response.Write(tw.ToString());
Response.End();
}
检查<form id="form1" runat="server">在,无丢失
protected void Page_Load(object sender, EventArgs e)
{
String strsql;
DataSet objDataset = new DataSet();
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["GoodsConnectionString"].ToString();
strsql = "select * from products";
SqlDataAdapter objAdapter = new SqlDataAdapter();
con.Open();
objAdapter.SelectCommand = new SqlCommand(strsql, con);
objAdapter.Fill(objDataset); //dgExcel是Gridview的id
DataView oView = new DataView(objDataset.Tables[0]);
dgExcel.DataSource = oView;
dgExcel.DataBind();
con.Close();
con.Dispose();
con = null;
if (Request.QueryString["bExcel"] == "1")//另一页面穿的值
{
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
dgExcel.RenderControl(hw);//程序在此出错
Response.Write(tw.ToString());
Response.End();
}
检查<form id="form1" runat="server">在,无丢失
解决方案 »
- 高分求将当前应用程序的目录装入到treeview中!
- 取TEXBOX里面的值
- 为什么在页面重定向前的标签框文本值设置不能及时显示出来?
- about dropdownlist 中控件的問題
- 准备用sql server 2000 + C#.net 开发管理系统请问数据表字段名用英文好还是用中文好?
- 站点配置问题。
- .net中怎样在程序中excel模板
- 说明: 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- 框架问题急~~~~~~~
- listbox的问题。。
- 求救,未能加载文件或程序集?
- 调用showModelessDialog打开非模式网页对话框为什么一闪而过?
public override void VerifyRenderingInServerForm( Control control )
{ }
{ }
里?