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);
                }
            }
        }

  • 相关阅读:
    一本通 1259:【例9.3】求最长不下降序列
    一本通 1258:【例9.2】数字金字塔
    洛谷 P1198 [JSOI2008]最大数
    洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
    【BZOJ1062】糖果雨(NOI2008)-数形结合+二维树状数组
    【BZOJ4070】雅加达的摩天楼(APIO2015)-分块+最短路
    【BZOJ2326】数学作业(HNOI2011)-递推+矩阵快速幂
    【BZOJ2734】集合选数(HNOI2012)-状压DP
    【BZOJ3213】抛硬币(ZJOI2013)-期望DP+KMP+高精度
    【BZOJ3590】Quare(SNOI2013)-状压DP
  • 原文地址:https://www.cnblogs.com/htht66/p/1961499.html
Copyright © 2011-2022 走看看