Analysis on the use of the Repeater control (export as is and dynamically display/hide columns in Repeater), analysis of repeater

Source: Internet
Author: User

Analysis on the use of the Repeater control (export as is and dynamically display/hide columns in Repeater), analysis of repeater

1. Original Repeater data export

DataTable dt = ViewState ["DtDatat"] as DataTable; // data source bound to Repeater this. repeater1.DataSource = dt; this. repeater1.DataBind (); DisplayDetailCol (false); // use stream to export Excel HttpContext. current. response. contentEncoding = System. text. encoding. default; HttpContext. current. response. contentType = "application/ms-excel"; HttpContext. current. response. charset = "gb2312"; HttpContext. current. response. appendHeader ("Content-Disposition", "attachment; filename =" + Context. server. urlPathEncode ("excel .xls"); // solve the Chinese garbled problem StringWriter sw = new StringWriter (); HtmlTextWriter htw = new HtmlTextWriter (sw); Digest (htw); HttpContext. current. response. write (sw. toString (); HttpContext. current. response. end ();

Ii. dynamically display/hide columns in Repeater

 foreach (RepeaterItem item in this.Repeater1.Controls)    {      if (item.ItemType == ListItemType.Header)      {        item.FindControl("panelDetail").Visible = b;      }      if (item.ItemType == ListItemType.Item)      {        item.FindControl("lbtnDetail").Visible = b;      }    }

3. The downloaded excel file is displayed in html format.

You need to add the <table> label to HeaderTemplate and FooterTemplate.

4. If the exported Excel Data is empty or the data is reduced to one column

Do not set the column width to percentage

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.