你有没有把DataGrid 放在<form runat=Server></form>里面啊

解决方案 »

  1.   

    我知道一点但是不知道对不对,给你个提示吧   你的那个控件没有放到<form></form>标签中才出现的那样的问题
      你导出到excel的语句也可能存在问题,我以前用你的"application/ms-excel"没有成功,改为
      "application/octet-stream"好像就可以了, 你试一试吧
      

  2.   

    我的页面代码如下:
    <form id="Form1" method="post" runat="server">
    <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%" align="center" background="images/treetopbg.jpg"
    border="0">
    <TR>
    <TD class="bk" width="10"><FONT face="宋体">&nbsp;</FONT></TD>
    <TD class="bk" width="25"><IMG height="16" src="images/staff.gif" width="16"></TD>
    <TD class="bk" height="30">首页 &gt;&gt; 人力资源管理 &gt;&gt; 员工基本信息
    <asp:label id="labParam" runat="server" Visible="False"></asp:label><asp:label id="labSelect" runat="server"></asp:label><asp:label id="aa" runat="server"></asp:label><asp:label id="lblSearch" runat="server" Visible="False"></asp:label></TD>
    </TR>
    </TABLE>
    <table cellSpacing="0" cellPadding="0" width="100%" align="center" bgColor="snow" border="0">
    <TR height="30">
    <TD colSpan="5" height="6"></TD>
    </TR>
    <TR height="30">
    <TD colSpan="5">&nbsp;&nbsp;&nbsp;&nbsp;按公司分类:<IMG height="12" src="images/acc.gif" width="12">&nbsp;
    <asp:linkbutton id="lnbCompanyft" runat="server">方特投资发展有限公司</asp:linkbutton><IMG height="12" src="images/acc.gif" width="12">&nbsp;
    <asp:linkbutton id="lnbCompanyzn" runat="server">华强智能技术有限公司</asp:linkbutton><IMG height="12" src="images/acc.gif" width="12">&nbsp;
    <asp:linkbutton id="lnbCompanysm" runat="server">华强数码电影有限公司</asp:linkbutton>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button id="btnExcel" runat="server" Text="导出EXCEL" CssClass="redButtonCss"></asp:Button><FONT face="宋体">&nbsp;</FONT>
    <asp:button id="cmdSearch" runat="server" CssClass="redButtonCss" Text="高级搜索"></asp:button><FONT face="宋体">&nbsp;</FONT>
    <asp:button id="Button1" runat="server" CssClass="redButtonCss" Text="生成报表"></asp:button><FONT face="宋体">&nbsp;</FONT>
    </TD>
    </TR>
    </table>
    <table cellSpacing="0" cellPadding="0" width="98%" align="center" border="0">
    <tr>
    <td height="8"><FONT face="宋体"></FONT></td>
    </tr>
    </table>
    <table cellSpacing="0" cellPadding="0" width="98%" align="center" border="0">
    <tr>
    <TD>
    <TABLE class="gbtext" id="Table2" cellSpacing="0" cellPadding="0" width="100%" border="0">
    <TR>
    <TD style="WIDTH: 70px" align="center" width="70" height="24"><asp:button id="btnAll" runat="server" CssClass="redbuttoncss" Width="60px" Text="全部员工"></asp:button></TD>
    <TD style="WIDTH: 70px" align="center" width="70" height="24"><asp:button id="btnOnduty" runat="server" CssClass="redbuttoncss" Width="60px" Text="在职员工"></asp:button></TD>
    <TD style="WIDTH: 70px" align="center" width="71" height="24"><asp:button id="btnOutduty" runat="server" CssClass="redbuttoncss" Width="60px" Text="离职员工"></asp:button></TD>
    <TD style="WIDTH: 75px" align="center" width="77" height="24"><asp:button id="btnWillon" runat="server" CssClass="redbuttoncss" Width="70px" Text="将转正员工"></asp:button></TD>
    <TD align="center"><asp:label id="lblShowCount" runat="server"></asp:label></TD>
    <TD style="WIDTH: 210px" align="right"><asp:button id="cmdNew" runat="server" CssClass="redbuttoncss" Text="新员工"></asp:button>&nbsp;<asp:button id="btnDimission" runat="server" CssClass="redbuttoncss" Text="离职"></asp:button>&nbsp;<asp:button id="btnChangePosition" runat="server" CssClass="redbuttoncss" Text="调职"></asp:button>&nbsp;<asp:button id="btnOn" runat="server" CssClass="redbuttoncss" Text="转正"></asp:button>&nbsp;&nbsp;</TD>
    </TR>
    <TR>
    <TD style="WIDTH: 70px" align="center" width="70" height="2"></TD>
    <TD style="WIDTH: 70px" align="center" width="70" height="2"></TD>
    <TD style="WIDTH: 71px" align="center" width="71" height="2"></TD>
    <TD style="WIDTH: 77px" align="center" width="77" height="2"></TD>
    <TD align="right"></TD>
    </TR>
    </TABLE>
    </TD>
    </tr>
    <tr>
    <td align="center"><asp:datagrid id="Employeeinfo" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True"
    BorderColor="#93BEE2" PageSize="20" DataKeyField="Einfo_number">
    <AlternatingItemStyle HorizontalAlign="Center" BackColor="#E8F4FF"></AlternatingItemStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Height="30px" ForeColor="White" BackColor="#337FB2"></HeaderStyle>
    <FooterStyle HorizontalAlign="Right"></FooterStyle>
    <Columns>
    <asp:BoundColumn DataField="Einfo_number" HeaderText="编号">
    <HeaderStyle Width="8%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_name" HeaderText="姓名">
    <HeaderStyle Width="10%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_sex" HeaderText="性别">
    <HeaderStyle Width="5%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_company" HeaderText="公司">
    <HeaderStyle Width="18%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_dep" HeaderText="部门">
    <HeaderStyle Width="10%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_depsmall" HeaderText="分部门">
    <HeaderStyle Width="10%"></HeaderStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Einfo_ontime" HeaderText="聘用时间">
    <HeaderStyle Width="10%"></HeaderStyle>
    </asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
    </asp:datagrid></td>
    </tr>
    </table>
    </form>
    这样好像是把DATAAGRID放在<FORM>和</FORM>之间了吧
      

  3.   

    对不起是我说的不明白,可能是你的某一个控件不在<form></form>内
    你的错误提示所说明的问题就是这个原因,如果不是这个问题,那我也不知道什么原因了
      

  4.   

    我如果将分页去掉,就OK了
    但我是肯定要分页的,所以请问一下有没有在分页情况下实现导出EXCEL的功能呀
      

  5.   

    直接把数据从数据库中导出到excel呀
      

  6.   

    接分 DataGrid中不只含有数据啊,还含有一些不能导入到Excel中 的 控件 ,写个过程把这些控件删除再导入就可以了
      

  7.   

    因为你加了分页, 这个是不对的。
    要从 DataGrid 导出数据必须不分页。 可以从它的数据源里取数据赋给你的方法, 然后方法里凭空创建一个不分页的 DataGrid 绑定这个数据源, 再 render 到页面即可。