zoukankan      html  css  js  c++  java
  • ASP.NET GridView控件匯出EXCEL移除控件,只是顯示文本

    ASP.NET GridView控件匯出EXCEL-移除控件,只是顯示文本
    下午 05:10 2011/2/22

    將GridView中的TextBox,DropDownList,LinkButton去掉,顯示文本。

        public void ClearGridControls(ref Control sourceControl)
        {
            for (int i = sourceControl.Controls.Count - 1; i >= 0; i += -1)
            {
                Control control = sourceControl.Controls[i];
                ClearGridControls(ref control);
            }

            if (!(sourceControl is TableCell))
            {
                Literal literal;

                if (sourceControl.GetType().GetProperty("SelectedItem") != null)
                {
                    //
                    // 下拉框
                    //

                    literal = new Literal();

                    // 顯示文本
                    sourceControl.Parent.Controls.Add(literal);

                    // 取內容
                    literal.Text = Convert.ToString(sourceControl.GetType().GetProperty("SelectedItem").GetValue(sourceControl, null));

                    // 移除
                    sourceControl.Parent.Controls.Remove(sourceControl);
                }
                else if (sourceControl.GetType().GetProperty("Text") != null)
                {
                    //
                    // 文本框
                    //

                    literal = new Literal();

                    sourceControl.Parent.Controls.Add(literal);

                    literal.Text = Convert.ToString(sourceControl.GetType().GetProperty("Text").GetValue(sourceControl, null));

                    sourceControl.Parent.Controls.Remove(sourceControl);
                }
            }
        }

  • 相关阅读:
    Jmeter对HTTP请求压力测试、并发测试的简单使用方法
    ActiveMQ学习笔记(4)----JMS的API结构和开发步骤
    SpringBoot项目如何进行打包部署
    ActiveMQ学习笔记(3)----JMS的可靠性机制
    狗屎一样的代码!快,重构我!
    代码对比工具,我就用这 6 个!
    Spring Boot 实现定时任务的 4 种方式
    阿里巴巴26个屌炸天的开源项目,你知道几个?
    centos7添加bridge-nf-call-ip6tables出现No such file or directory
    mysql国内镜像下载网址
  • 原文地址:https://www.cnblogs.com/htht66/p/1961499.html
Copyright © 2011-2022 走看看