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


C# DataGrid.RenderControl方法代码示例

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


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

示例1: save

        private void save(DataTable dt,string filename)
        {
            DataGrid excel = new DataGrid();
            System.Web.UI.WebControls.TableItemStyle AlternatingStyle = new TableItemStyle();
            System.Web.UI.WebControls.TableItemStyle headerStyle = new TableItemStyle();
            System.Web.UI.WebControls.TableItemStyle itemStyle = new TableItemStyle();
            AlternatingStyle.BackColor = System.Drawing.Color.LightGray;
            headerStyle.BackColor = System.Drawing.Color.LightGray;
            headerStyle.Font.Bold = true;
            headerStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            itemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; ;

            excel.AlternatingItemStyle.MergeWith(AlternatingStyle);
            excel.HeaderStyle.MergeWith(headerStyle);
            excel.ItemStyle.MergeWith(itemStyle);
            excel.GridLines = GridLines.Both;
            excel.HeaderStyle.Font.Bold = true;
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            excel.DataSource = ds;   //输出DataTable的内容
            excel.DataBind();

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

            Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".xls");
            Response.ContentType = "application/ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.Write(oHtmlTextWriter.InnerWriter.ToString());
            Response.End();
        }
开发者ID:bsimp6983,项目名称:BackupDashes,代码行数:32,代码来源:ExportXLS.aspx.cs

示例2: DataTable2Excel

        /// <summary>
        /// 导出Excel文件,转换为可读模式
        /// </summary>
        public static void DataTable2Excel(System.Data.DataTable dtData)
        {
            DataGrid dgExport = null;
            HttpContext curContext = HttpContext.Current;
            StringWriter strWriter = null;
            HtmlTextWriter htmlWriter = null;

            if (dtData != null)
            {
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
                curContext.Response.Charset = "";
                strWriter = new StringWriter();
                htmlWriter = new HtmlTextWriter(strWriter);
                dgExport = new DataGrid();
                dgExport.DataSource = dtData.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();
                try
                {
                    dgExport.RenderControl(htmlWriter);
                }
                catch (Exception e)
                {
                    Log4Net.LogWrite("err", e.Message);
                }
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }
开发者ID:wawa0210,项目名称:jgq,代码行数:33,代码来源:ExcelHelper.cs

示例3: ExportToExcelFile

        /// <summary>
        /// Exporta la información a Excel.
        /// </summary>
        /// <param name="response">HttpResponse actual.</param>
        /// <param name="data">Datos a exportar.</param>
        /// <param name="nombreArchivo">Nombre del archivo Excel</param>
        public static void ExportToExcelFile(HttpResponse response, DataView data, string nombreArchivo)
        {
            var dg = new DataGrid { DataSource = data };
            dg.DataBind();

            response.Clear();
            response.Buffer = true;

            //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            response.AddHeader("Content-Disposition", "filename=" + nombreArchivo);
            response.ContentType = "application/vnd.ms-excel";
            response.Charset = "UTF-8";
            response.ContentEncoding = System.Text.Encoding.Default;

            var stringWriter = new StringWriter();
            var htmlWriter = new HtmlTextWriter(stringWriter);
            dg.RenderControl(htmlWriter);

            response.Write(stringWriter.ToString());
            //resp.Flush();
            try
            {
                response.End();
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                throw ex;
            }
        }
开发者ID:preguntoncojonero,项目名称:test,代码行数:36,代码来源:ISExcel.cs

示例4: Convert

    public static void Convert(System.Data.DataSet ds, System.Web.HttpResponse response, string ExcelName)
    {
        try
        {
            //first let's clean up the response.object
            response.Clear();
            response.Charset = "";
            //set the response mime type for excel

            response.ContentType = "application/vnd.ms-excel";
            //create a string writer
            //response.AddHeader("Content-Disposition", "attachment;filename=Shilpa.xls");

            response.AddHeader("Content-Disposition", "attachment;filename=" + ExcelName + ".xls");

            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            //create an htmltextwriter which uses the stringwriter
            System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
            //instantiate a datagrid
            System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
            //set the datagrid datasource to the dataset passed in
            dg.DataSource = ds.Tables[0];
            //bind the datagrid
            dg.DataBind();
            //tell the datagrid to render itself to our htmltextwriter
            dg.RenderControl(htmlWrite);
            //all that's left is to output the html
            response.Write(stringWrite.ToString());
            response.End();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
开发者ID:BInny1,项目名称:United-Car-Exchange,代码行数:35,代码来源:DataSetToExcel.cs

示例5: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var r = context.HttpContext.Response;
            r.Clear();
            r.ContentType = "application/vnd.ms-excel";
            if (!string.IsNullOrEmpty(FileName))
                r.AddHeader("content-disposition",
                    "attachment;filename=" + FileName);
            const string header =
@"<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">
<head>
    <meta http-equiv=Content-Type content=""text/html; charset=utf-8"">
    <style>
    <!--table
    br {mso-data-placement:same-cell;}
    tr {vertical-align:top;}
    -->
    </style>
</head>
<body>";
            r.Write(header);
            r.Charset = "";

            var dg = new DataGrid();
            dg.EnableViewState = false;
            dg.DataSource = Data;
            dg.DataBind();
            dg.RenderControl(new HtmlTextWriter(r.Output));
            r.Write("</body></HTML>");
        }
开发者ID:stevesloka,项目名称:bvcms,代码行数:30,代码来源:ExcelResult.cs

示例6: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;

            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.xls");
            Response.Charset = "";

            var name = "ExtraExcelResult " + DateTime.Now;
            var tag = DbUtil.Db.PopulateSpecialTag(qid, DbUtil.TagTypeId_ExtraValues);

            var roles = CMSRoleProvider.provider.GetRolesForUser(Util.UserName);
            var xml = XDocument.Parse(DbUtil.Db.Content("StandardExtraValues.xml", "<Fields/>"));
            var fields = (from ff in xml.Root.Elements("Field")
                          let vroles = ff.Attribute("VisibilityRoles")
                          where vroles != null && (vroles.Value.Split(',').All(rr => !roles.Contains(rr)))
                          select ff.Attribute("name").Value);
            var nodisplaycols = string.Join("|", fields);

            var cmd = new SqlCommand("dbo.ExtraValues @p1, @p2, @p3");
            cmd.Parameters.AddWithValue("@p1", tag.Id);
            cmd.Parameters.AddWithValue("@p2", "");
            cmd.Parameters.AddWithValue("@p3", nodisplaycols);
            cmd.Connection = new SqlConnection(Util.ConnectionString);
            cmd.Connection.Open();

            var dg = new DataGrid();
            dg.DataSource = cmd.ExecuteReader();
            dg.DataBind();
            dg.RenderControl(new HtmlTextWriter(Response.Output));
        }
开发者ID:hkouns,项目名称:bvcms,代码行数:32,代码来源:ExtraExcelResult.cs

示例7: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     //if (Session["Type"].ToString() == "Excel")
     //{
     DataSet ds = Session["ExcelDs"] as DataSet;
     Response.Clear();
     Response.Charset = "";
     Response.ContentType = "application/vnd.ms-excel";
     Response.AddHeader("Content-Disposition", "attachment;filename=ExcelName.xls");
     System.IO.StringWriter stringWrite = new System.IO.StringWriter();
     System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
     System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
     dg.DataSource = ds.Tables[0];
     dg.DataBind();
     dg.RenderControl(htmlWrite);
     Response.Write(stringWrite.ToString());
     Response.End();
     //}
     //else
     //{
     //    Response.ContentType = "application/pdf";
     //    string path = Server.MapPath("~/PDFS/TestM10.pdf");
     //    byte[] bts = System.IO.File.ReadAllBytes(path);
     //    Response.Clear();
     //    Response.ClearHeaders();
     //    Response.AddHeader("Content-Type", "Application/octet-stream");//octet-stream
     //    Response.AddHeader("Content-Length", bts.Length.ToString());
     //    Response.AddHeader("Content-Disposition", "attachment;   filename=1.pdf");
     //    Response.BinaryWrite(bts);
     //    Response.Flush();
     //    Response.TransmitFile(path);
     //    Response.End();
     //}
 }
开发者ID:hugo-mirad,项目名称:Test-car-sales,代码行数:34,代码来源:DownloadPageTest.aspx.cs

示例8: UploadDataTableToExcel

 private void UploadDataTableToExcel(DataTable feedBacks)
 {
     HttpResponse response = HttpContext.Current.Response;
     try
     {
         response.Clear();
         response.Charset = string.Empty;
         response.ContentType = "application/vnd.ms-excel";
         response.AddHeader("Content-Disposition", "attachment;filename=\"FeedBack.xls\"");
         using (StringWriter stringWriter = new StringWriter())
         {
             using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter))
             {
                 DataGrid dataGrid = new DataGrid();
                 dataGrid.DataSource = feedBacks;
                 dataGrid.DataBind();
                 dataGrid.RenderControl(htmlTextWriter);
                 response.Write(stringWriter.ToString());
             }
         }
         response.End();
     }
     catch (ThreadAbortException ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
     }
 }
开发者ID:dheerajmishra77,项目名称:TCPedia,代码行数:27,代码来源:download.aspx.cs

示例9: ToExcel

    public void ToExcel(object sender, System.EventArgs e)
    {
        try
        {
            DataTable dtData = GetDTList();
            System.Web.UI.WebControls.DataGrid dgExport = null;
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;

            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;

            if (dtData != null && dtData.Rows.Count > 0)
            {
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                curContext.Response.Charset = "UTF-8";
                curContext.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312 >");

                strWriter = new System.IO.StringWriter();
                htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
                dgExport = new System.Web.UI.WebControls.DataGrid();
                dgExport.DataSource = dtData.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();

                for (int i = 0; i < dgExport.Items.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        dgExport.Items[i].Cells[j].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                    }
                }

                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
                WriteAlertInfo(AlertSuccess);
            }
            else
            {
                WriteAlertInfo(AlertNoData);
            }
        }
        catch (FisException fe)
        {
            this.GridViewExt1.DataSource = GetTable();
            this.GridViewExt1.DataBind();
            writeToAlertMessage(fe.mErrmsg);
        }
        catch (Exception ex)
        {
            this.GridViewExt1.DataSource = GetTable();
            this.GridViewExt1.DataBind();
            writeToAlertMessage(ex.Message);
        }
        finally
        {
            endWaitingCoverDiv();
        }
    }
开发者ID:wra222,项目名称:testgit,代码行数:60,代码来源:DTPalletControl.aspx.cs

示例10: ExportToExcel

        public void ExportToExcel(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                string filename = "Test1234.xls";
                string excelHeader = "Quiz Report";

                System.IO.StringWriter tw = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
                DataGrid dgGrid = new DataGrid();
                dgGrid.DataSource = dt;
                dgGrid.DataBind();

                // Report Header
                hw.WriteLine("<b><u><font size=’3′> " + excelHeader + " </font></u></b>");

                //Get the HTML for the control.
                dgGrid.RenderControl(hw);

                //Write the HTML back to the browser.
                Response.ContentType = "application/vnd.ms-excel";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
                this.EnableViewState = false;
                Response.Write(tw.ToString());
                Response.End();
            }
        }
开发者ID:usuresh,项目名称:CloudApp,代码行数:27,代码来源:Default.aspx.cs

示例11: GetHtmlTagsfromDatagrid

 private static System.IO.StringWriter GetHtmlTagsfromDatagrid(DataTable datatable)
 {
     System.IO.StringWriter stringWriter = new System.IO.StringWriter();
     HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter);
     DataGrid dg = new DataGrid();
     dg.DataSource = datatable;
     dg.DataBind();
     dg.RenderControl(htmlWrite);
     return stringWriter;
 }
开发者ID:nullqube,项目名称:Michael-Sync-s-blog-sample,代码行数:10,代码来源:Default.aspx.cs

示例12: ExportarExcel

 public void ExportarExcel(DataGrid grid)
 {
     this.Response.Clear();
     this.Response.AddHeader("content-disposition", "attachment;filename=Arquivo.xls");
     this.Response.Charset = "";
     this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
     this.Response.ContentType = "application/vnd.xls";
     StringWriter sWr = new StringWriter();
     HtmlTextWriter hWr = new HtmlTextWriter(sWr);
     grid.RenderControl(hWr);
     this.Response.Write(sWr.ToString());
     this.Response.End();
 }
开发者ID:fabioss,项目名称:Intouch,代码行数:13,代码来源:exportaExcel.aspx.cs

示例13: ExecuteResult

 public override void ExecuteResult(ControllerContext context)
 {
     var Response = context.HttpContext.Response;
     Response.Buffer = true;
     Response.ContentType = "application/vnd.ms-excel";
     Response.AddHeader("Content-Disposition", "attachment;filename=CMSOrganizations.xls");
     Response.Charset = "";
     var d = m.OrganizationExcelList();
     var dg = new DataGrid();
     dg.DataSource = d;
     dg.DataBind();
     dg.RenderControl(new HtmlTextWriter(Response.Output));
 }
开发者ID:rossspoon,项目名称:bvcms,代码行数:13,代码来源:OrgExcelResult.cs

示例14: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;

            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=CMSStatusFlags.xls");
            Response.Charset = "";

            var collist = from ss in DbUtil.Db.ViewStatusFlagNamesRoles.ToList()
                          where ss.Role == null || HttpContext.Current.User.IsInRole(ss.Role)
                          select ss;

            IEnumerable<string> cq = null;

            if (flags.HasValue())
                cq = from f in flags.Split(',')
                     join c in collist on f equals c.Flag
                     select "\tss.{0} as [{0}_{1}]".Fmt(c.Flag, c.Name);
            else
                cq = from c in collist
                     where c.Role == null || HttpContext.Current.User.IsInRole(c.Role)
                     select "\tss.{0} as [{1}]".Fmt(c.Flag, c.Name);

            var tag = DbUtil.Db.PopulateSpecialTag(qid, DbUtil.TagTypeId_StatusFlags);
            var cols = string.Join(",\n", cq);
            var cn = new SqlConnection(Util.ConnectionString);
            cn.Open();
            var cmd = new SqlCommand(@"
            SELECT
            md.PeopleId,
            md.[First],
            md.[Last],
            md.Age,
            md.Marital,
            md.Decision,
            md.DecisionDt,
            md.JoinDt,
            md.Baptism,
            " + cols + @"
            FROM StatusFlagColumns ss
            JOIN MemberData md ON md.PeopleId = ss.PeopleId
            JOIN dbo.TagPerson tp ON tp.PeopleId = md.PeopleId
            WHERE tp.Id = @p1", cn);
            cmd.Parameters.AddWithValue("@p1", tag.Id);
            var rd = cmd.ExecuteReader();
            var dg = new DataGrid();
            dg.DataSource = rd;
            dg.DataBind();
            dg.RenderControl(new HtmlTextWriter(Response.Output));
        }
开发者ID:vs06,项目名称:bvcms,代码行数:51,代码来源:StatusFlagsExcelResult.cs

示例15: btnReport_Click

        protected void btnReport_Click(object sender, EventArgs e)
        {
            LogicaNegocio.AconpanaClase aconpanaClase = new LogicaNegocio.AconpanaClase();
               // List<ModeloNegocio.Asesor> listUsuario = new List<ModeloNegocio.Asesor>();

            // NOW ASSIGN DATA TO A DATAGRID.
            DataGrid dg = new DataGrid();
            dg.DataSource = aconpanaClase.getReportAllAconpanaClase();
            dg.DataBind();

            // THE EXCEL FILE.
            string sFileName = "Segui-Clase-" + System.DateTime.Now.Date + "-.xls";
            sFileName = sFileName.Replace("/", "");

            // SEND OUTPUT TO THE CLIENT MACHINE USING "RESPONSE OBJECT".
            Encoding encoding = Encoding.UTF8;
            Response.ClearContent();
            Response.Buffer = true;
            //Response.Charset = encoding.EncodingName;
            //Response.ContentEncoding = System.Text.Encoding.UTF8;

            Response.Charset = encoding.EncodingName ;
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("Windows-1252");
            Response.AddHeader("content-disposition", "attachment; filename=" + sFileName);
            Response.ContentType = "application/vnd.ms-excel";
            //Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            //Response.AppendHeader("content-disposition", "attachment; filename=myfile.xlsx");
            EnableViewState = false;

            System.IO.StringWriter objSW = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter objHTW = new System.Web.UI.HtmlTextWriter(objSW);

            dg.HeaderStyle.Font.Bold = true;     // SET EXCEL HEADERS AS BOLD.
            dg.HeaderStyle.ForeColor = Color.White;
            dg.HeaderStyle.BackColor = Color.Blue;

            dg.RenderControl(objHTW);

            // STYLE THE SHEET AND WRITE DATA TO IT.
            Response.Write("<style> TABLE { border:solid 1px #999; } " +
                "TD { border:solid 1px #000000; text-align:center } </style>");
            Response.Write(objSW.ToString());

            // ADD A ROW AT THE END OF THE SHEET SHOWING A RUNNING TOTAL OF PRICE.
            //Response.Write("<table><tr><td><b>Total: </b></td><td></td><td><b>" +
            //dTotalPrice.ToString("N2") + "</b></td></tr></table>");

            Response.End();
        }
开发者ID:jcdiaz356,项目名称:educacionfinaciera,代码行数:49,代码来源:Admin-SeguiClase.aspx.cs


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