Esempio n. 1
0
 /// <summary>
 /// ���캯����
 /// </summary>
 /// <param name="gridView">gridView<see cref="DataGridView"/>��</param>
 public ExportData(DataGridView gridView)
     : this(gridView.Page)
 {
     if (gridView == null)
         throw new ArgumentNullException("gridView");
     this.gridView = gridView;
 }
        /// <summary>
        /// 生成并注册弹出普通窗口的脚本。
        /// </summary>
        /// <param name="owner"></param>
        private void BuildNormalWin(DataGridView owner)
        {
            if (owner != null)
            {
                ClientScriptManager scriptManager = owner.Page.ClientScript;
                string columnSign = this.DataField;
                string scriptKey = string.Format("{0}_{1}_OpenNormal", owner.ClientID, columnSign);
                if (!scriptManager.IsClientScriptBlockRegistered(scriptKey))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<script type=\"text/javascript\">");
                    sb.AppendFormat("function {0}_{1}_OpenNormal(strUrl)", owner.ClientID, columnSign);
                    sb.Append("{");
                    sb.AppendFormat("window.open(strUrl,'{0}','height={1},width={2},status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');",
                                    this.Target, this.WinHeight, this.WinWidth);
                    sb.Append("}");
                    sb.Append("</script>");

                    scriptManager.RegisterClientScriptBlock(this.GetType(), scriptKey, sb.ToString());
                }
            }
        }
        /// <summary>
        /// 生成并注册弹出模式窗口的脚本。
        /// </summary>
        /// <param name="owner"></param>
        private void BuildModalWin(DataGridView owner)
        {
            if (owner != null)
            {
                ClientScriptManager scriptManager = owner.Page.ClientScript;
                string columnSign = this.DataField;
                string scriptKey = string.Format("{0}_{1}_OpenModal", owner.ClientID, columnSign);
                if (!scriptManager.IsClientScriptBlockRegistered(scriptKey))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<script type=\"text/javascript\">\r\n");
                    sb.AppendFormat("function {0}_{1}_OpenModal(strUrl)\r\n",
                            owner.ClientID,
                            columnSign);
                    sb.Append("{\r\n");
                    sb.Append("\tvar vTmd=Math.random();\r\n");
                    sb.Append("\tvar vReturn='';\r\n");
                    sb.Append("\tif(strUrl.indexOf('?')>-1)\r\n");
                    sb.Append("\t{\r\n");
                    sb.AppendFormat("\t\tvReturn=window.showModalDialog(strUrl+'&tmd='+vTmd,null,'dialogWidth:{0};dialogHeight:{1};help:0');\r\n",
                        this.WinWidth,
                        this.WinHeight);
                    sb.Append("\t}\r\n");
                    sb.Append("\telse\r\n");
                    sb.Append("\t{\r\n");
                    sb.AppendFormat("\t\tvReturn=window.showModalDialog(strUrl+'?tmd='+vTmd,null,'dialogWidth:{0};dialogHeight:{1};help:0');\r\n",
                        this.WinWidth,
                        this.WinHeight);
                    sb.Append("\t}\r\n");

                    sb.Append("\tif(typeof(vReturn)!=\"undefined\" && vReturn!=\"\")\r\n");
                    sb.Append("\t{\r\n");
                    sb.AppendFormat("\t\t{0}\r\n", scriptManager.GetPostBackEventReference(owner, owner.ClientID));

                    sb.Append("\t}\r\n");

                    sb.Append("}\r\n");
                    sb.Append("</script>\r\n");
                    scriptManager.RegisterClientScriptBlock(this.GetType(), scriptKey, sb.ToString());
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// �������ݡ�
        /// </summary>
        /// <returns></returns>
        public virtual StringWriter Export(DataGridView gView, ExportFileType fileType)
        {
            StringWriter sw = new StringWriter();
            if (gView != null)
            {
                string split = (fileType == ExportFileType.txt ? "\t" : ",");
                DataControlFieldExCollection columns = gView.Columns;
                sw.WriteLine(this.RemoveHtmlTag(this.ExportHeader(columns, split)));

                DataGridViewRowCollection rows = gView.Rows;
                foreach (DataGridViewRow row in rows)
                    sw.WriteLine(this.RemoveHtmlTag(this.ExportItem(row, columns, split)));
            }
            return sw;
        }