Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Post the code you have tried.

1 solution

Please try the below way....

XML
<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>


C#
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();
        }
 
Share this answer
 
Comments
xpertzgurtej 14-Dec-15 23:19pm    
Thanks Rajdeep. I got the idea with your help. With little modification i was able to achieve my goal..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900