Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I want to export data from list view.I tried the following code snippet:

C#
    try
    {
        Response.Buffer = true;
        Response.ContentType = "application/x-msexcel";
        Response.AddHeader("Content-Disposition", "attachment; filename=asdf.xls");
        Response.ContentEncoding = Encoding.UTF8;
        Response.Charset = "";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        if (dropdown1.SelectedValue=="1")
        {
            listview.RenderControl(hw);
        }
        Response.Write(sw.ToString());
        Response.End();
    }
    catch (Exception ex)
    {
       //catching exception
    }
}


In this am obtaining the output but the data are exported as <HTML> tag formats.Help me to export only the data from the list view.
HTML
<thead>
<tr>
</tr>
</thead>

          <tr>
              <td>data</td>
              <td>data</td>
              <td style="text-align:center;">data</td>
              <td  style="text-align:right;">data</td>
          </tr>

          <tr>
              <td>data</td>
              <td>data</td>
              <td style="text-align:center;">data</td>
              <td  style="text-align:right;">data</td>
          </tr>

          <tr>
              <td>data</td>
              <td>data</td>
              <td style="text-align:center;">data</td>
              <td  style="text-align:right;">data</td>
          </tr>

          <tr>
              <td>data</td>
              <td>data</td>
              <td style="text-align:center;">data</td>
              <td  style="text-align:right;">data</td>
          </tr>


Please provide a solution to obtain only the data.
Posted

1 solution

This is quite often asked question. Please, next time use SearchBox[^] on the right-top corner of this site.

Have a look at similar question: listview data write to excel using c#[^]
 
Share this answer
 
Comments
Sabari Karthik 9-Dec-13 23:49pm    
I already looked after the search box. But all the details are given only for c# I'm in need of asp.net code.

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