我又写个简单的小例子,这次没有母版页:aspx的代码是
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="C1GRIDVIEW.aspx.cs" Inherits="WebApplication1.QCM.C1GRIDVIEW" %>
<%@ Register assembly="C1.Web.UI.Controls.2" namespace="C1.Web.UI.Controls.C1GridView" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:C1GridView ID="T1" runat="server" UseEmbeddedVisualStyles="True" VisualStyle="Vista" ></cc1:C1GridView>
<asp:Button ID="gggg" runat="server" OnClick="btn_click" />
</div>
</form>
</body>
</html>
cs代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1.QCM
{
public partial class C1GRIDVIEW : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String sqlstr = "select * from BQE_IPRECORD";
publicclass.GeneralCommon gl = new publicclass.GeneralCommon();
int rnt = 0;
int cnt = 0;
System.Data.DataTable dt = gl.exe_sql_table(sqlstr, ref rnt, ref cnt);
C1.Web.UI.Controls.C1GridView.C1GridView T1 = (C1.Web.UI.Controls.C1GridView.C1GridView)this.form1.FindControl("T1");
T1.DataSource = dt;
T1.DataBind();
}
protected void btn_click(object sender, EventArgs e)
{
C1.Web.UI.Controls.C1GridView.C1GridView T1 = (C1.Web.UI.Controls.C1GridView.C1GridView)this.form1.FindControl("T1");
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
T1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
}
}
仍然报错:
类型“C1GridView”的控件“T1”必须放在具有 runat=server 的窗体标记内。 |