locked
Repeater values Export to Excel-C#.NET RRS feed

  • Question

  • User-1578974752 posted

    Hi

    I have a repeater which have a table. When i click the Export to excel button , i need to show the values in to Excel in the same way i am seeing in the repeater.

    If I use grid view , i can see same format, but when i put repeater, all the values are coming in the Excel as a single line.

    Can please help.

    Thanks

    Friday, November 13, 2020 3:36 AM

Answers

  • User1535942433 posted

    Hi shsu,

    Accroding to your description,do you set css in your repeater?You could post your codes to us.It will help us to solve your problems.

    Since you don't post your codes,I have created a test. Just like this:

     <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <table border="1">
                        <tr>
                            <td style="width: 100px">
                                <%#Eval("Id") %>
                            </td>
                            <td style="width: 100px">
                                <%#Eval("num") %>
                            </td>
                            <td style="width: 100px">
                                <%#Eval("total")%>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>
            <br />
            <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click"/>

    Code-behind:

     protected void btnExport_Click(object sender, EventArgs e)
            {
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=RepeaterExport.xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                Repeater1.RenderControl(hw);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2020 3:08 AM