为GirdView添加CSS样式

首先要定义一个样式,比如下面这个:
<style type="text/css">
.text
{
font-size
: 9px;
color
: #00f;
background
: 1px solid #cf0;
}
</style>

然后在aspx页面里,给Gridview添加OnRowDataBound="GridView1_RowDataBound",最后在cs页面写GridView1_RowDataBound的方法,在方法里给GridView相应行添加样式,代码如下:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[
1].Attributes.Add("class""text");
            e.Row.Cells[2
].Attributes.Add("class""text");
            e.Row.Cells[
3].Attributes.Add("class""text");
        }
}
原文地址:https://www.cnblogs.com/youth0826/p/995238.html