简体   繁体   English

如何使用C#在gridview中设置字体颜色和大小?

[英]How to Set font-color and size in gridview using c#?

I'm exporting temporary DataGrid to PDF by using the Following Code, 我正在使用以下代码将临时DataGrid导出为PDF,

        System.Data.DataTable dt = new System.Data.DataTable();
        CDbAccess db = new CDbAccess();
        IDbConnection conn = db.GetConnectionInterface();
        conn.Open();

        IDbCommand cmd = db.GetCommandInterface(str);

        IDbDataAdapter da = db.GetDataAdapterInterface(cmd);
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();

        try
        {
            da.SelectCommand = cmd;
            da.Fill(ds);
            dt = ds.Tables[0];
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            conn.Close();
            // da.Dispose();
            conn.Dispose();
        }

        GridView GridView1 = new GridView();
        GridView1.AllowPaging = false;
        GridView1.DataSource = dt;
        GridView1.DataBind();
        GridView1.HeaderStyle.BackColor = System.Drawing.Color.DeepSkyBlue;

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition",
            "attachment;filename=BugReport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.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();

And the Output is looking worse, so that i need to align the Output. 而且输出看起来更糟,所以我需要调整输出。

And i just want to set Font color and Font Size to particular column. 我只想将“字体颜色”和“字体大小”设置为特定的列。

How to set it using C#? 如何使用C#进行设置?

Columns属性引用网格视图设置中的列,如果您只想访问特定行中的目标列,则:

GridView1.Rows[0].Cells[0].ControlStyle.Font.Size = 40;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM