如何在DataGrid中更改数据的字体样式 [英] How to change the font style of the data in DataGrid

查看:457
本文介绍了如何在DataGrid中更改数据的字体样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用ASP和VB.NET.
在用来自SQL的数据填充数据网格之后,我想根据一些条件标准更改数据的字体样式.就像,我有一列说年级,如果学生获得"A"年级,则对应的数据行应为粗体和CAPS字体.如果学生获得"B"级成绩,则相应的数据行应以粗体显示.所有其他年级学生的数据行都使用常规字体.

所以请帮帮我!!

Hi,

I am working with ASP and VB.NET.
After the data grid populated with the data from SQL, I want to change the font style of the data based on some condition criteria. It''s like, I have a column say Grade, If the Students got ''A'' Grade, the corresponding data row''s should be Bold and CAPS in font. If the students got ''B'' Grade, the corresponding data row should in Bold in font. All Other Grades student''s data rows in normal font like that.

So plz help me !!!

推荐答案

使用RowDataBound事件更改单个单元格或整个行.

简单的示例代码:

Use the RowDataBound event to alter individual cells or the entire row.

Simple sample code:

// Only work with data rows.
if (e.Row.RowType == DataControlRowType.DataRow)
{
    // Some condition to isolate the row or cell of interest...
    if (e.Row.Cells[0].Text == "foo")
    {
        // Do something to a cell.
        e.Row.Cells[7].Font.Bold = true;

        // Do to the whole row.
        e.Row.Font.Bold = true;
    }
}


这篇关于如何在DataGrid中更改数据的字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆