Asp. File output stream mode of GridView in Net-practical tips

Source: Internet
Author: User

Asp. NET provides a variety of data server controls for displaying table data from a database in a Web page, one of which is the GridView control. This control is almost the same as the DataGridView control we have learned before, so we are not unfamiliar with the GridView control.

Step One: set up the columns you need for the GridView, bind the data, my first column of data because the database is stored in the "Moon and Minutes" format, in the output, I gave it a dataformatstring value “{0:yyyy-MM-dd}”,The format of the month and year, so that the output to the time format is 2016-08-07, looks also beautiful some

The second step: binding the data, write the query method, and then directly datasource binding your query method, and then

Bind your GridView so that the value you need gets the

Step Three:

Except for the For loop part, the rest according to I write on it, I this is a node of the file output, if you just want to show you grdview all the data output output, you directly write the code of the GridView data source is good, and then add a loop J's, I'm using the StringBuilder, data stitching, a column that shows what I need

Fourth Step: Set a button click event in the page, call this method, the file automatically generated, based on the date generated, date generated code is: Response.AddHeader(@"Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("_yyyyMMdd_HHmmss") + ".txt"); You can also modify its stitching format.

Summarize

The above is the asp.net in the GridView file output flow mode of the entire content, I hope this article for you to learn the Asp.ne in the GridView Help.

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.