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.