{
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
string excelFileName = "测试Excel档案.xls";
Context.Response.ContentType = "application/x-excel";
Context.Response.AddHeader("content-disposition", "p_w_upload;filename=" +
Server.UrlEncode(excelFileName));
this.GridView1.RenderControl(hw);
Context.Response.Write(tw.ToString());
Context.Response.End();
}
{
// 如果系结的资料列不是 GridView 控制项的页首,
// 则将资料列第一个栏位之 Label 控制项的文字设定为「资料列数加1」,
// 以便代表资料编号。
if (e.Row.RowType != DataControlRowType.Header)
{
e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
}
}