如何将转发器数据导出为ex​​cel。 [英] How to export repeater data to excel.

查看:83
本文介绍了如何将转发器数据导出为ex​​cel。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在转发器中,我在文字中显示产品名称,在它们前面有一个文本框来输入数量。并且每个项目前面都有一个复选框来选择产品

例如



产品名称数量

肥皂12(文本框)

牙膏2(文本框)

发油5(文本框)





现在我想将数据从转发器导出到excel。我能够这样做,但在excel表中它显示文本框和复选框,每条记录都是原样。我不想要这个。应该有简单的文本而不是文本框,复选框列应该隐藏

In repeater I am showing Product Name in literal and in front of them there is a textbox to entere the quantity. And there is a checkbox in front of every item to select product
e.g

Product Name Quantity
Soap 12(textbox)
Tooth Paste 2(textbox)
Hair Oil 5(textbox)


Now i want to export the data from repeater to excel. I was able to do so but in excel sheet it show textbox and checkbox with each record as it is. I don't want this. There should be simple text instead of textbox and checkbox column should be hidden

推荐答案

请尝试以下方式....



Please try the below way....

<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
             <itemtemplate>
                 <table style="width: 100%;">
                     <tr>
                         <td><asp:label id="Label1" runat="server" text="<%#Eval("ProductName") %>"></asp:label></td>
                         <td><asp:textbox id="TextBox1" runat="server" text="<%#Eval("Amount") %>"></asp:textbox></td>
                     </tr>
                 </table>
            </itemtemplate>
        </asp:repeater>







protected void Button1_Click(object sender, EventArgs e)
        {
            var sb = new StringBuilder();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=Details.xls");
            Response.Charset = "";
            Response.ContentType = "application/excel";
            sb.Append("<table border="1">");
            foreach (RepeaterItem item in Repeater1.Items)
            {
                sb.Append("<tr>");
                sb.Append("<td>");
                sb.Append(((Label)item.FindControl("Label1")).Text);
                sb.Append("<td>");
                sb.Append("<td>");
                sb.Append(((TextBox)item.FindControl("TextBox1")).Text);
                sb.Append("<td>");
                sb.Append("</td></td></td></td></tr>");
            }
            sb.Append("</table>");
            Response.Write(sb.ToString());
            Response.End();
        }


这篇关于如何将转发器数据导出为ex​​cel。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆