首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net vs2008,gridview导出excel时怎么取消其中的超链接?注意:不是模板列

2013-11-21 
asp.net vs2008,gridview导出excel时如何取消其中的超链接?注意:不是模板列gridview的前台代码:asp:GridV

asp.net vs2008,gridview导出excel时如何取消其中的超链接?注意:不是模板列
gridview的前台代码:
<asp:GridView ID="GridView1" runat="server" Width="1024px"
                AutoGenerateColumns="False" AllowPaging="True" 
                onpageindexchanging="GridView1_PageIndexChanging" 
                onrowdatabound="GridView1_RowDataBound" PageSize="20">            
            <RowStyle HorizontalAlign="Center" />
            <Columns>
                <asp:BoundField DataField="ID" Visible="false" />
                <asp:BoundField HeaderText="序號" />
                <asp:HyperLinkField DataTextField="EXCEPTION_NO" HeaderText="單號" 
                    DataNavigateUrlFields="ID" 
                    DataNavigateUrlFormatString="~/Details.aspx?ID={0}" />
                <asp:BoundField DataField="CREATE_BY" HeaderText="填單人" />
                <asp:BoundField DataField="CREATE_DATE" HeaderText="填單時間" DataFormatString="{0:d}" />
                <asp:BoundField DataField="CREATE_CLASS" HeaderText="課別" />                    
                <asp:BoundField DataField="EXCEP_SYS" HeaderText="異常系統" />                
                <asp:TemplateField HeaderText="問題描述">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("EXCEPTION_DESC") %>' ToolTip=<%# Eval("EXCEPTION_DESC")%>></asp:Label>
                    </ItemTemplate>                  
                </asp:TemplateField>
                <asp:BoundField DataField="SOLUTION" HeaderText="解決辦法" />
                <asp:BoundField DataField="EXCEP_STATUS" HeaderText="單據狀態" />               
               
            </Columns>
        </asp:GridView>

导出按钮的后台代码为:

 //导出 Excel 文件   
        protected void btn_excel_Click(object sender, EventArgs e)
        {           
                Response.Clear();
                Response.BufferOutput = true;
                //设定输出的字符集
                Response.Charset = "GB2312";
                //假定导出的文件名为FileName.xls
                Response.AppendHeader("Content-Disposition", "attachment;filename=BuglistCollection.xls");
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                //设置导出文件的格式
                Response.ContentType = "application/ms-excel";


                //关闭ViewState
                EnableViewState = false;
                System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
                System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
                System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
                // 将有分页的GridView中的数据全部导出到Excel
                this.GridView1.AllowPaging = false;
                this.Select_query_style(); //选择查询类型                                

                GridView1.RenderControl(textWriter);
                //把HTML写回浏览器
                Response.Write(stringWriter.ToString()); 
                Response.End();
                this.GridView1.AllowPaging = true;
                this.Select_query_style(); //选择查询类型
}
导出后效果:
asp.net vs2008,gridview导出excel时怎么取消其中的超链接?注意:不是模板列
[解决办法]
直接把源数据写入到excel中

热点排行