当前位置: 首页>>代码示例>>C#>>正文


C# GridView.RenderControl方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.GridView.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# GridView.RenderControl方法的具体用法?C# GridView.RenderControl怎么用?C# GridView.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.GridView的用法示例。


在下文中一共展示了GridView.RenderControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

        public ActionResult Index()
        {
            StringWriter stringWriter = new StringWriter();

            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
            {
                string classValue = "className";
                writer.RenderBeginTag(HtmlTextWriterTag.Html);

                writer.AddAttribute(HtmlTextWriterAttribute.Class, classValue);
                writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "#db4141");
                writer.Write("Huy");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.RenderEndTag();

                writer.RenderEndTag();
                GridView grid = new GridView();
                grid.AllowPaging = false;
                grid.RenderControl(writer);
                //Change the Header Row back to white color
                DataTable[] dt = new DataTable[2];

                for (int i = 0; i <= 1; i++)
                {
                    dt[i] = new DataTable();
                    dt[i].Columns.Add("id");
                    dt[i].Columns.Add("name");
                }

                IHTMLBuilder htmlBuilder = new HTMLBuilder();
                htmlBuilder.Build();

                grid.DataSource = dt;
                grid.DataBind();
                //Apply style to Individual Cells
                grid.HeaderRow.Cells[0].Text = "harrison";
                grid.HeaderRow.Cells[0].Style.Add("background-color", "green");

                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition",
                 "attachment;filename=GridViewExport.xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                Dictionary<string, IdentityModels> test = new Dictionary<string, IdentityModels>();
                test.Add("huy", new IdentityModels());
                var testModel =  test["huy"];

            }
            Response.Output.Write(stringWriter.ToString());
            Response.Flush();
            Response.End();
            return View();
        }
开发者ID:huyjack178,项目名称:harrsion-project,代码行数:54,代码来源:HomeController.cs

示例2: btnExcel_Click

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = BindGridView();
            GridView1.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=" + DateTime.Now.Year + "-Newly_Hired" + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }
            GridView1.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
开发者ID:ismaeljaycarpio,项目名称:vs2013,代码行数:31,代码来源:NewlyHired.aspx.cs

示例3: GetUserExcelList

        public ActionResult GetUserExcelList(string searchType, string searchText, int? page, int? rows)
        {
            var grid = new System.Web.UI.WebControls.GridView();
            List<UserT> model = new UserBiz().GetUserList(searchType, searchText, page.Value, rows.Value);

            grid.DataSource = from m in model
                              select new
                              {
                                  LoginId = m.LoginId,
                                  LastLoginDate = m.LastLoginDate,
                                  IsDeleted = m.IsDeleted,
                                  DeletedDate = m.DeletedDate,
                                  InsertUser = m.InsertUser,
                                  InsertDate = m.InsertDate,

                              };

            grid.DataBind();

            Response.ClearContent();

            Response.AddHeader("content-disposition", string.Format("attachment; filename=Excel_{0}.xls", DateTime.Now.ToString("yyyyMMddhhmmss")));
            Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=" + Request.ContentEncoding.HeaderName + "'>");
            Response.Buffer = true;

            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            return View("Index");
        }
开发者ID:ByunSeungHyun,项目名称:AssetManagementSystem,代码行数:34,代码来源:UserController.cs

示例4: generaXLS

        protected void generaXLS(string reporte, string campos, string sql)
        {
            GridView GridView2 = new GridView();
            GridView2.AllowPaging = false;
            GridView2.DataSource = obtienDatosTabla(campos, sql);
            GridView2.DataBind();
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + reporte + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView2.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView2.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView2.RenderControl(hw);
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:27,代码来源:frmGenRep.aspx.cs

示例5: generatePDFButton_Click

        protected void generatePDFButton_Click(object sender, EventArgs e)
        {
            DataTable aDataTable = aPatientManager.GetData(Convert.ToInt64(voterIdTextBox.Text));

            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.ShowHeaderWhenEmpty = true;
            GridView1.DataSource = aDataTable;
            GridView1.DataBind();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=AllHistoryOfAPatient.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter aStringWriter = new StringWriter();
            HtmlTextWriter aHtmlTextWriter = new HtmlTextWriter(aStringWriter);
            GridView1.RenderControl(aHtmlTextWriter);
            StringReader aStringReader = new StringReader(aStringWriter.ToString());
            Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker aHtmlWorker = new HTMLWorker(pdfDocument);
            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            pdfDocument.Open();
            aHtmlWorker.Parse(aStringReader);
            pdfDocument.Close();
            Response.Write(pdfDocument);
            Response.End();
        }
开发者ID:MirajHossain,项目名称:Community-Medicine-System,代码行数:26,代码来源:PatientHistoryUI.aspx.cs

示例6: btnDownload_Click

        protected void btnDownload_Click(object sender, ImageClickEventArgs e)
        {
            Response.Clear();

            Response.AddHeader("content-disposition", "attachment; filename=Baogia.xls");

            Response.Charset = "";

            Response.ContentType = "application/vnd.xls";

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);

            DataSet dts = new DataSet();
            SqlDataAdapter adt = new SqlDataAdapter();
            SqlCommand comm = new SqlCommand("Export_to_Excel", objConn.SqlConn());
            comm.CommandType = CommandType.StoredProcedure;
            comm.Connection.Open();
            adt.SelectCommand = comm;
            adt.Fill(dts);

            GridView g = new GridView();
            g.DataSource = dts;
            g.DataBind();

            g.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString());

            Response.End();
        }
开发者ID:phamtuanchip,项目名称:tmdt,代码行数:33,代码来源:Right.ascx.cs

示例7: ExportProductData

        public ActionResult ExportProductData()
        {
            // string ss = "<table><td><td></table>";
               var products = Session["Product"];
               GridView gv = new GridView();
               gv.DataSource = products;
               gv.DataBind();
               Response.ClearContent();
               Response.Buffer = true;
               Response.AddHeader("content-disposition", "attachment; filename=Orderlist.xls");
               Response.ContentType = "application/ms-excel";
               Response.Charset = "";
               StringWriter sw = new StringWriter();
               HtmlTextWriter htw = new HtmlTextWriter(sw);
               gv.RenderControl(htw);
               Response.Output.Write(sw.ToString());
               Response.Flush();
               Response.End();

               //Response.ClearContent();
               //Response.AddHeader("content-disposition", "attachment; filename=Orderlist.xls");
               //Response.ContentType = "application/ms-excel";
               //Response.Write(ss);
               //Response.End();

               return RedirectToAction("Reports");
        }
开发者ID:jasimuddin534,项目名称:jasim_basis,代码行数:27,代码来源:ReportsController.cs

示例8: ExportData

        /// <summary>
        /// 将GridView数据导出Excel
        /// </summary>
        /// <param name="obj"></param>
        public void ExportData(GridView obj)
        {
            try
            {
                string style = "";
                if (obj.Rows.Count > 0)
                {
                    style = @"<style> .text { mso-number-format:\@; } </script> ";
                }
                else
                {
                    style = "no data.";
                }

                HttpContext.Current.Response.ClearContent();
                DateTime dt = DateTime.Now;
                string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportData" + filename + ".xls");
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Charset = "GB2312";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                obj.RenderControl(htw);
                HttpContext.Current.Response.Write(style);
                HttpContext.Current.Response.Write(sw.ToString());
                HttpContext.Current.Response.End();
            }
            catch
            {

            }
        }
开发者ID:ShuiMuQinHua,项目名称:net_libiary,代码行数:37,代码来源:ExportExcel.cs

示例9: OutPutExcelByGridView

        public static void OutPutExcelByGridView(GridView grvExcel, string excelName, string encodingName, System.Globalization.CultureInfo ci)
        {
            //定义文档类型、字符编码
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Charset = encodingName;
            //下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开
            //filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc    .xls    .txt   .htm
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(excelName));
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(encodingName);
            //Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
            HttpContext.Current.Response.ContentType = "application/ms-excel";

            grvExcel.EnableViewState = false;
            if (ci == null) ci = new System.Globalization.CultureInfo("zh-CN", true);
            System.Globalization.CultureInfo myCultureInfo = ci;

            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCultureInfo);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            oHtmlTextWriter.Write("<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=gb2312\"></head>");

            grvExcel.Visible = true;
            grvExcel.RenderControl(oHtmlTextWriter);
            //this 表示输出本页,你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
            HttpContext.Current.Response.Write(oStringWriter.ToString());
            HttpContext.Current.Response.End();
        }
开发者ID:popotans,项目名称:hjnlib,代码行数:28,代码来源:ReportUtil.cs

示例10: CreateSendExcellFile

        public async Task<FileResult> CreateSendExcellFile()
        {
            List<Report> report = await db.FilesDownloadNotes.Include(f => f.ApplicationUser).Include(f => f.FilesUploadNote)
                                         .Select(x => new Report
                                         {
                                             FileName = x.FilesUploadNote.Name,
                                             FileFileSize = x.FilesUploadNote.Size,
                                             FileType = x.FilesUploadNote.Type,
                                             DataUploaded = x.FilesUploadNote.DataTimeUpload,
                                             WhoUploaded = x.FilesUploadNote.UserName,
                                             TypeOperations = x.FileOperations,
                                             DataOperations = x.DateTimeDownload,
                                             WhoOperations = x.ApplicationUser.UserName
                                         }).ToListAsync();
 
            GridView grid = new GridView();
            grid.DataSource = report;
            grid.DataBind();
            StringWriter sw = new StringWriter(); 
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            string r_name = "Report_" + DateTime.Now.ToString() + "_.xls";

            return File(Encoding.UTF8.GetBytes(sw.ToString()), "application/ms-excel", r_name);
        }
开发者ID:Run-L,项目名称:FileTransferMonitor,代码行数:25,代码来源:FilesDownloadNotesController.cs

示例11: ExportToExcel

        public void ExportToExcel(DataTable dataTable, HttpResponse response)
        {
            // Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
            response.Charset = "";
            response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView1.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            // style to format numbers to string
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            response.Write(style);
            response.Output.Write(sw.ToString());
            response.Flush();
            response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:29,代码来源:GenReportes.cs

示例12: ExportClientsListToExcel

        public void ExportClientsListToExcel()
        {
            var grid = new System.Web.UI.WebControls.GridView();
            string[] ClientsList={"mike","jonh","vladimit"};
            grid.DataSource = /*from d in dbContext.diners
                              where d.user_diners.All(m => m.user_id == userID) && d.active == true */
                              from d in ClientsList
                              select new
                              {
                                  FirstName = d
                              };

            grid.DataBind();

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=Exported_Diners.xls");
            Response.ContentType = "application/excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            Response.Write(sw.ToString());

            Response.End();
        }
开发者ID:poledustaren,项目名称:FindRussianWords,代码行数:26,代码来源:ExcelController.cs

示例13: ExportToPDF

        protected void ExportToPDF(DataTable dt)
        {
            GridView gvExport = new GridView();
            gvExport.AllowPaging = false;
            gvExport.DataSource = dt;
            gvExport.DataBind();

            gvExport.HeaderRow.Style.Add("font-size", "10px");
            gvExport.HeaderRow.Style.Add("font-weight", "bold");
            gvExport.Style.Add("text-decoration", "none");
            gvExport.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
            gvExport.Style.Add("font-size", "8px");

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=LinkSpace.pdf");

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            gvExport.RenderControl(hw);

            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }
开发者ID:WebKredApp,项目名称:MyWebKred,代码行数:33,代码来源:LinkSpaceCRUDController.aspx.cs

示例14: GridViewToExcel

        /// <summary>
        /// GridView导出到Excel
        /// </summary>
        /// <param name="gvBindData"></param>
        /// <param name="strExcelName">文件名</param>
        /// <param name="strCharset">编码类型</param>
        /// <param name="page">默认当前页面</param>
        public static void GridViewToExcel(GridView gvBindData, string strExcelName = "GridView", string strCharset = "GB2312", Page page = null)
        {
            gvBindData.AllowPaging = false;
            gvBindData.DataBind();
            for (int i = 0; i < gvBindData.Columns.Count; i++)
            {
                if (gvBindData.Columns[i].FooterText.IndexOf("Delete") >= 0)
                {
                    gvBindData.Columns[i].Visible = false;
                }
            }
            if (page == null)
            {
                page = ((Page)HttpContext.Current.Handler);
            }

            page.Response.Clear();
            page.Response.Buffer = false;
            page.Response.Charset = strCharset;
            page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strExcelName, Encoding.UTF8) + ".xls");
            page.Response.ContentEncoding = Encoding.GetEncoding(strCharset);
            page.Response.ContentType = "application/ms-excel";
            StringWriter oStringWriter = new StringWriter();
            HtmlTextWriter writer = new HtmlTextWriter(oStringWriter);
            gvBindData.RenderControl(writer);
            page.Response.Write(oStringWriter.ToString());
            page.Response.End();
            gvBindData.AllowPaging = true;
        }
开发者ID:hsjun,项目名称:HNAS.Framework4.1,代码行数:36,代码来源:Function.cs

示例15: ExportToExcel

        public ActionResult ExportToExcel()
        {
            try
            {
                list = (List<NhanVien>)TempData["list"];
                if (list != null)
                {
                    GridView gv = new GridView();
                    gv.DataSource = list;
                    gv.DataBind();
                    Response.ClearContent();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment; filename=DanhSachNhanVienVeHuu.xls");
                    Response.ContentType = "application/ms-excel";
                    Response.Charset = "";
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);
                    gv.RenderControl(htw);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    return Content("<script language='javascript' type='text/javascript'>alert('Không thể xuất file excel');");
                }

                return RedirectToAction("VeHuu");
            }
            catch (Exception)
            {

                throw;
            }
        }
开发者ID:xaydungpmtheomohinhphanlop,项目名称:QL_Nhan_Vien_Luong,代码行数:35,代码来源:ThongKeController.cs


注:本文中的System.Web.UI.WebControls.GridView.RenderControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。