GridView自定義分頁---派生類(5)

 /// <summary>
        /// 重新綁定所有資料,不做分頁
        /// </summary>
        private void DataBindForExcel()
        {
            SetDataSource(true);

            TotalPage = -1;

            this.DataBind();
        }

        /// <summary>
        /// 重新綁定所有資料
        /// </summary>
        public void ReDataBind()
        {
            SetDataSource(false);
            
            this.DataBind();
        }

        #region 清除gridview子元件

        /// <summary>
        /// 設定Cell的文字為元件的Text屬性
        /// </summary>
        private void RenderDataToText()
        {
            string[] arrIdx = ExportExcelClearControlIndex.Split(',');

            foreach (GridViewRow row in this.Rows)
            {
                foreach (string idx in arrIdx)
                {
                    TableCell cell = row.Cells[Convert.ToInt16(idx)];

                    if (cell.HasControls())
                    {
                        string cellText = "";

                        foreach (Control ctl in cell.Controls)
                        {
                            string value = "";

                            if (ctl.GetType().GetProperty("SelectedItem") != null)
                            {
                                value =
                                    ctl.GetType().GetProperty("SelectedItem").GetValue(ctl, null).ToString();
                            }
                            else if (ctl.GetType().GetProperty("Text") != null)
                            {
                                value =
                                    ctl.GetType().GetProperty("Text").GetValue(ctl, null).ToString();
                            }

                            if (value.Trim().Length > 0)
                            {
                                cellText += TrimHref(value.Trim()) + "  ";
                            }
                        }

                        cell.Text = cellText;
                    }
                    else
                    {
                        cell.Text = TrimHref(cell.Text);
                    }
                  
                }
            }
        }

        /// <summary>
        /// 移除連結字申
        /// </summary>
        /// <param name="value">欄位文字</param>
        /// <returns>已移除連結字申的欄位文字</returns>
        private string TrimHref(string value)
        {
            if (value.ToLower().IndexOf("<a") > -1 && value.ToLower().IndexOf("</a>") > -1)
            {
                string pattent = @"<a(.*?)</a>";

                List<string> linkInfos = new List<string>();

                MatchCollection matches = Regex.Matches(value, pattent, RegexOptions.IgnoreCase);

                foreach (Match match in matches)
                {
                    linkInfos.Add(Regex.Replace(
                        Regex.Replace(match.Value, "<a(.*?)>", "", RegexOptions.IgnoreCase),
                        "</a>", "", RegexOptions.IgnoreCase));
                }

                return String.Join(Environment.NewLine, linkInfos.ToArray());
            }

            return value;
        }
 
        #endregion
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值