日期:2014-05-17  浏览次数:20440 次

导出绑有dropdownlist控件到EXCEL报错?如何改一下呢?
我在datagrid中绑定了一个dropdownlist下拉控件.我在导出的时候好像是连这个控件一块导出来的,报错:如下:

类型“Button”的控件“ctl00_ContentPlaceHolder1_DataGrid1_ctl02_ctl00”必须放在具有 runat=server 的窗体标记内。 
错误行: DataGrid1.RenderControl(oHtmlTextWriter);下面加红了!
现在是如何改一下?不让这个控件导出来,让他的值导出来就可以?
C# code


          <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" AllowSorting="True" OnCancelCommand="DataGrid1_CancelCommand" OnEditCommand="DataGrid1_EditCommand" OnItemDataBound="DataGrid1_ItemDataBound" OnUpdateCommand="DataGrid1_UpdateCommand" DataKeyField="nid">
              <Columns>
                  <asp:BoundColumn DataField="sendtime" HeaderText="呼叫时间" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="workercallerid" HeaderText="主叫坐席" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="SendCallerID" HeaderText="被叫电话" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="setcallerid" HeaderText="显示号码" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="workerhold" HeaderText="坐席通话时长" ReadOnly="True"></asp:BoundColumn>
                    <asp:BoundColumn DataField="sendhold" HeaderText="用户通话时长" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="fee" HeaderText="呼叫费用" ReadOnly="True"></asp:BoundColumn>
                  <asp:TemplateColumn HeaderText="营销结果">
                        <ItemTemplate>
                        <%# DataBinder.Eval(Container.DataItem,"lbmc") %>
                        </ItemTemplate>
                      <EditItemTemplate>
                          &nbsp;<asp:DropDownList ID="dep_jieguo" runat="server">
                          </asp:DropDownList>
                      </EditItemTemplate>
                  </asp:TemplateColumn>
                  <asp:BoundColumn DataField="jieguo" HeaderText="结果ID" ReadOnly="True"></asp:BoundColumn>
                  <asp:BoundColumn DataField="RecFile" HeaderText="录音" ReadOnly="True"></asp:BoundColumn>
                  <asp:EditCommandColumn ButtonType="PushButton" CancelText="取消" EditText="编辑" HeaderText="操作"
                      UpdateText="更新"></asp:EditCommandColumn>
                      
              </Columns></asp:DataGrid>

后台导出代码如下:
C# code
        CheckAdInfoSort();
        FirstBindData();
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToShortDateString() + ".xls");
        Response.ContentEncoding = System.Text.Encoding.UTF7;

        //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
        Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件