首页 新闻 会员 周边 捐助

Repeater导出excel时遇到的问题

0
[已解决问题] 解决于 2013-05-23 08:32

后台代码:   

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "utf-8";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("名称", System.Text.Encoding.UTF8) + ".xls");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");     //设置输出流为简体中文       
        Response.ContentType = "application/ms-excel";    //设置输出文件类型为excel文件。        
        this.EnableViewState = false;       
        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);       
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);       
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); //   repeater控件的ID      
        rpt_storeinfo.RenderControl(oHtmlTextWriter);       
        Response.Write(oStringWriter.ToString());       
        Response.End();
    }

前台代码:

<asp:Repeater ID="rpt_storeinfo" runat="server" OnItemDataBound="rpt_storeinfo_ItemDataBound" >
                            <ItemTemplate>
                                <tr id="tr_info" runat="server" style="height: 22px">
                                    <td style='background-color: white;' align="right">
                                        <%# Eval("Belong").ToString().ToUpper()%><br><%#Eval("BelongN").ToString()%>
                                    </td>
                                    <td align="center">
                                        <asp:Label ID="lbl_date" runat="server" Text='<%# Eval("riqi","{0:d}") %>' />&nbsp;
                                    </td>
                                    <td style="display: none;">
                                        <asp:HiddenField ID="hidden_Belong" runat="server" Value='<%# Eval("Belong") %>' />
                                        <asp:HiddenField ID="hidden_amount" runat="server" Value='<%# Eval("amount") %>' />
                                        <asp:Label ID="lbl_amount" runat="server" Text='<%# Eval("amount").ToString()=="0"?"<span style=color:red;font-size:12px>无库存纪录</span>":"库存:"+Eval("amount").ToString()+" - " %>' />
                                        <asp:Label ForeColor="Blue" ID="lbl_PDtime" runat="server" Text='<%# Eval("pdTime","{0:d}") %>' />
                                    </td>
                                    <td>
                                        <asp:Label ID="lbl_ID" runat="server" Text='<%# Eval("bianhao") %>' />
                                    </td>
                                    <td align="right">
                                        <asp:Label ID="lbl_WL" runat="server" Text='<%# Eval("WLbianhao") %>'/><br>
                                        <asp:Label ID="lbl_PM" runat="server" Text='<%# Eval("pinmingguige") %>'/>
                                    </td>
                                    <td align="right">
                                        <asp:Label ID="lbl_LaiQty" runat="server" Text='<%# Eval("LaiQty") %>' />&nbsp;
                                    </td>
                                    <td align="right">
                                        <asp:Label ID="lbl_OutQty" runat="server" Text='<%# Eval("OutQty") %>' />&nbsp;
                                    </td>
                                    <td style="font-size: 14px; font-weight: bold;" align="right">
                                        <asp:Label ID="lbl_jieyu" runat="server" />&nbsp;
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                <tr>
                                    <td colspan="9">
                                        <%# ((System.Data.DataTable)ViewState["store"]).Rows.Count == 0 ? "<font color=red>无记录</font>":""%>
                                    </td>
                                </tr>
                            </FooterTemplate>
                        </asp:Repeater>

遇到的问题是:HiddenField”的控件“ctl00_ctpMaster_rpt_storeinfo_ctl00_hidden_Belong”必须放在具有 runat=server 的窗体标记内

NothingHave的主页 NothingHave | 初学一级 | 园豆:6
提问于:2013-05-22 17:22
< >
分享
最佳答案
0

    在页面中重写Page基类的VerifyRenderingInServerForm方法(加在后台代码中)
     public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm control is rendered for
    }

且:<form id="form1" runat="server"

奖励园豆:5
yyutudou | 小虾三级 |园豆:997 | 2013-05-22 17:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册