Gridview导出的问题与图像一起出色 [英] problem with Gridview export to excel along with image

查看:49
本文介绍了Gridview导出的问题与图像一起出色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中包含两个列中的进度条和图像。当我尝试导出gridview整个页面正在导出而不是只导出gridview。如何只导出网格视图以及进度条和图像而不是整个页面?

I have a gridview which contain progress bar and image in two of its columns. when i try to export the gridview entire page is being exported instead of only gridview. How to export only grid view along with progressbar and image instead of entire page?

推荐答案

你可以试试

导出到Excel工具







使用此方法

You can try
Export To Excel Utility

or

use this method
public static void PrepareGridViewForExport(Control gridView)
    {
        for (int i = 0; i < gridView.Controls.Count; i++)
        {
            //Get the control
            Control currentControl = gridView.Controls[i];
            if (currentControl is LinkButton)
            {
                gridView.Controls.Remove(currentControl);
                gridView.Controls.AddAt(i, new LiteralControl((currentControl as LinkButton).Text));
            }
            else if (currentControl is ImageButton)
            {
                gridView.Controls.Remove(currentControl);
                gridView.Controls.AddAt(i, new LiteralControl((currentControl as ImageButton).AlternateText));
            }
            else if (currentControl is HyperLink)
            {
                gridView.Controls.Remove(currentControl);
                gridView.Controls.AddAt(i, new LiteralControl((currentControl as HyperLink).Text));
            }
            else if (currentControl is DropDownList)
            {
                gridView.Controls.Remove(currentControl);
                gridView.Controls.AddAt(i, new LiteralControl((currentControl as DropDownList).SelectedItem.Text));
            }
            else if (currentControl is CheckBox)
            {
                gridView.Controls.Remove(currentControl);
                gridView.Controls.AddAt(i, new LiteralControl((currentControl as CheckBox).Checked ? "True" : "False"));
            }
            if (currentControl.HasControls())
            {
                // if there is any child controls, call this method to prepare for export
                PrepareGridViewForExport(currentControl);
            }
        }
    }





和导出按钮点击事件



电话



and on export button click event

call

PrepareGridViewForExport(gridView1);



然后导出excel代码


and then export to excel code


这篇关于Gridview导出的问题与图像一起出色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆