| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1992 人关注过本帖
标题:用户代码未处理HttpException
只看楼主 加入收藏
maque0532
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-1-14
收藏
 问题点数:0 回复次数:2 
用户代码未处理HttpException
类型“GridView”的控件"toexcelto"必须放在具有runat=server的窗体标记内。
我的前台代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="toexcel1.aspx.cs" Inherits="toexcel1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" method="post" runat="server">
    <div runat="server">
        <table style="width: 377px; height: 123px" runat="server">
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                    <asp:GridView ID="toexcelto" runat="server" BackColor="White" BorderColor="#3366CC"
                        BorderStyle="None" BorderWidth="1px" CellPadding="4">
                        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                        <Columns>
                            <asp:BoundField DataField="ProductID" HeaderText="商品号" />
                            <asp:BoundField DataField="ProductName" HeaderText="商品名称" />
                            <asp:BoundField DataField="UnitPrice" HeaderText="商品单价" />
                        </Columns>
                        <RowStyle BackColor="White" ForeColor="#003399" />
                        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
            </tr>
        </table>
        
    </div>
    </form>
</body>
</html>

后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using
using System.Text;
using System.Data.SqlClient;
public partial class toexcel1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bandexcel();
        }
    }
    private void bandexcel()
    {
        SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
        conn1.Open();
        string cmdtext = "select top 5 * from products";
        SqlDataAdapter sa = new SqlDataAdapter(cmdtext,conn1);
        DataSet ds = new DataSet();
        sa.Fill(ds,"excel");
        toexcelto.DataSource=ds.Tables["excel"].DefaultView;
        toexcelto.DataBind();
        conn1.Close();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "gb2312";
        EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        toexcelto.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }
}


请问各位大哥们我该怎么处理这个问题啊 烦死了 书上的案例运行的时候正常 为什么我的就不能呢 跪求啊
搜索更多相关主题的帖子: runat DTD 代码 server 
2008-04-02 21:51
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
你要用这个必须在后台写个重载方法
 public override void VerifyRenderingInServerForm(Control control)
    {
 
    }
2008-04-02 22:17
maque0532
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-1-14
收藏
得分:0 
谢谢朋友你对我讲解
谢谢朋友你对我讲解
2008-04-03 21:16
快速回复:用户代码未处理HttpException
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037512 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved