0

我在我的 Web 项目中添加了一个全新的“Global.asax”文件,并在尝试构建它时出现以下错误:

'指令控制未知'。

我在网上读到的所有解决方案都在谈论由“复制粘贴”引起的错误。

有人可以帮忙吗?

4

1 回答 1

0
public void exportGrid(GridView GV)
{


    System.Web.HttpContext.Current.Response.Clear();


    System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

    System.Web.HttpContext.Current.Response.Charset = "";

    //System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

    System.Web.HttpContext.Current.Response.ContentType = "application/vnd.xls";

    System.IO.StringWriter stringWrite = new System.IO.StringWriter();

    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    GV.RenderControl(htmlWrite);

    System.Web.HttpContext.Current.Response.Write(stringWrite.ToString());

    System.Web.HttpContext.Current.Response.End();

}
protected void Export_click(object sender, EventArgs e)
{

    if (!((Radfromdate.SelectedDate == null) || (Radtodate.SelectedDate == null) || (Fromtime.SelectedDate == null) || (Totime.SelectedDate == null)))
    {
        DateTime date = Radfromdate.SelectedDate.Value;
        string fromdate = date.ToShortDateString().ToString();
        DateTime dt = Fromtime.SelectedDate.Value;
        string starttime = fromdate + " " + dt.ToLongTimeString().ToString();
        DateTime date2  = Radtodate.SelectedDate.Value;
        string todate = date2.ToShortDateString().ToString();
        DateTime dt1 = Totime.SelectedDate.Value;
        string endtime = todate + " " + dt1.ToLongTimeString().ToString();
        DataSet ds = new DataSet();
        ds = DataAccessLayer.Binddata(starttime, endtime);

        ds.Tables[0].Columns.Remove("statusT1");
        ds.Tables[0].Columns.Remove("statusT2");
        ds.Tables[0].Columns.Remove("statusT3");
        ds.Tables[0].Columns.Remove("statusT4");
        ds.Tables[0].Columns.Remove("statusT5");
        ds.Tables[0].Columns.Remove("hhmmss");
        ds.Tables[0].Columns.Remove("InputStatus");
        GridView gvExport = new GridView();
        gvExport.DataSource = ds;
        gvExport.DataBind();
        exportGrid(gvExport);
        gvExport.Dispose();
    }

}

于 2012-11-19T09:06:03.553 回答