BelowCodeThe DataGrid is generated into a Word document and displayed in IE
// Generate
Httpcontext. Current. response. appendheader ("content-disposition", "attachment?filename=roadrepair.doc "); /? "
Response. contenttype = "application/vnd. MS-word"; // specify the file generation type.
Httpcontext. Current. response. charset = "";
Httpcontext. Current. response. contentencoding = system. Text. encoding. default;
System. Io. stringwriter Tw = new system. Io. stringwriter ();
System. Web. UI. htmltextwriter hW = new system. Web. UI. htmltextwriter (TW)
Datagrid1.rendercontrol (HW); // convert the DataGrid to a string
Httpcontext. Current. response. Write (HW. tosting ());
Httpcontext. Current. response. End ();
// Display
Response. clearcontent ();
Response. clearheaders ();
Response. contenttype = "application/MSWord ";
Response. writefile ("roadrepair.doc ");
Response. Flush ();
Response. Close ();