---
title: "从gridview里导出到EXCEL文件vb.net和C#代码 "
author: "awark"
date: "2011-09-26T11:10:11Z"
tags: []
categories: ["编程语言"]
slug: "gridview-excel-vb-net-c"
draft: false
lastmod: "2011-09-26T11:10:11Z"
id: 1180452
url: "https://awark.iteye.com/blog/1180452"
---

''vb.net源码  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;%@ Page Language="VB" %&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;script runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Function CreateDataSource()Function CreateDataSource() As ICollection   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim dt As System.Data.DataTable = New System.Data.DataTable   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim dr As System.Data.DataRow   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) dt.Columns.Add(New System.Data.DataColumn("id", GetType(Int32)))   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) dt.Columns.Add(New System.Data.DataColumn("PkID", GetType(String)))   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) dt.Columns.Add(New System.Data.DataColumn("Title", GetType(String)))   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim i As Integer = 0   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) While i &lt; 6   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   dr = dt.NewRow   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   dr(0) = i   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   dr(1) = "123456789123456789123456789"   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   dr(2) = "&lt;a href='http://dotnet.aspx.cc/'&gt;欢迎光临【孟宪会之精彩世界】&lt;/a&gt;"   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   dt.Rows.Add(dr)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   System.Math.Min(System.Threading.Interlocked.Increment(i),i-1)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End While   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim dv As System.Data.DataView = New System.Data.DataView(dt)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Return dv   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)End Function   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Protected Sub Page\_Load()Sub Page\_Load(ByVal sender As Object, ByVal e As EventArgs)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If Not IsPostBack Then   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   GridView1.BorderWidth = Unit.Pixel(2)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   GridView1.BorderColor = System.Drawing.Color.DarkOrange   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   GridView1.DataSource = CreateDataSource   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   GridView1.DataBind   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)End Sub   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Protected Sub Button1\_Click()Sub Button1\_Click(ByVal sender As Object, ByVal e As System.EventArgs)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.Clear   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.Buffer = True   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.Charset = "GB2312"   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls")   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.ContentEncoding = System.Text.Encoding.UTF7   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.ContentType = "application/ms-excel"   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Me.GridView1.RenderControl(oHtmlTextWriter)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.Output.Write(oStringWriter.ToString)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.Flush   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Response.End   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)End Sub   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Public Overloads Overrides Sub VerifyRenderingInServerForm()Sub VerifyRenderingInServerForm(ByVal control As Control)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)End Sub   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Protected Sub GridView1\_RowDataBound()Sub GridView1\_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) If e.Row.RowType = DataControlRowType.DataRow Then   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   e.Row.Cells(1).Attributes.Add("style", "vnd.ms-excel.numberformat:@;")   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) End If   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)End Sub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/script&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;head id="Head1" runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;title&gt;将 GridView 导出到 Excel 文件中&lt;/title&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/head&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;form id="form1" runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1\_RowDataBound"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      AutoGenerateColumns="false"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      &lt;Columns&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="序号" DataField="id" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="身份证号" DataField="PkID" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="网址" DataField="Title" ReadOnly="true" HtmlEncode="false" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      &lt;/Columns&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;/asp:GridView&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:Literal ID="HiddenOut" runat="server" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:Button ID="Button1" runat="server" Text="导出" OnClick="Button1\_Click" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;/form&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/html&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

 

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//C#源码  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;%@ Page Language="C#" EnableEventValidation="false" %&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;script runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  ICollection CreateDataSource( )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)  ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    System.Data.DataTable dt = new System.Data.DataTable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    System.Data.DataRow dr;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    dt.Columns.Add(new System.Data.DataColumn("id", typeof(Int32)));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    dt.Columns.Add(new System.Data.DataColumn("PkID", typeof(string)));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    dt.Columns.Add(new System.Data.DataColumn("Title", typeof(string)));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    for (int i = 0; i &lt; 6; i++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      dr = dt.NewRow();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      dr\[0] = i;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      dr\[1] = "123456789123456789123456789";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      dr\[2] = "&lt;a href='http://dotnet.aspx.cc/'&gt;欢迎光临【孟宪会之精彩世界】&lt;/a&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      dt.Rows.Add(dr);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    System.Data.DataView dv = new System.Data.DataView(dt);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    return dv;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)  }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  protected void Page\_Load( object sender, EventArgs e )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)  ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    if (!IsPostBack)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      GridView1.BorderWidth = Unit.Pixel(2);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      GridView1.BorderColor = System.Drawing.Color.DarkOrange;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      GridView1.DataSource = CreateDataSource();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      GridView1.DataBind();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)  }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  protected void Button1\_Click( object sender, System.EventArgs e )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)  ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.Clear();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.Buffer = true;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.Charset = "GB2312";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码！！！  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.ContentEncoding = System.Text.Encoding.UTF7;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    this.GridView1.RenderControl(oHtmlTextWriter);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.Output.Write(oStringWriter.ToString());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.Flush();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    Response.End();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)  }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  public override void VerifyRenderingInServerForm( Control control )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)  ...{ }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  protected void GridView1\_RowDataBound( object sender, GridViewRowEventArgs e )  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)  ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    if (e.Row.RowType == DataControlRowType.DataRow)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)    ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)      e.Row.Cells\[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)    }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)  }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/script&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;head runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;title&gt;将 GridView 导出到 Excel 文件中&lt;/title&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/head&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;form id="form1" runat="server"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1\_RowDataBound"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      AutoGenerateColumns="false"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      &lt;Columns&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="序号" DataField="id" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="身份证号" DataField="PkID" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;asp:BoundField HeaderText="网址" DataField="Title" ReadOnly="true" HtmlEncode="false" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)      &lt;/Columns&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;/asp:GridView&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:Literal ID="HiddenOut" runat="server" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;asp:Button ID="Button1" runat="server" Text="导出" OnClick="Button1\_Click" /&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  &lt;/form&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/html&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)