我正在尝试更改asp.net网格视图的水平和垂直线的颜色。我正在更改单元格边框颜色,但只更改了水平线。你可以看到附上的图片。
答案 0 :(得分:5)
您可以使用RowDataBound
:
protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-right:3px solid red; border-bottom:3px solid blue";
}
}
当然你也可以使用CSS类(通过tc.CssClass
)代替内联css。
答案 1 :(得分:1)
删除所有边框并执行以下操作, 在Grid View标记中添加以下代码行。
CellPadding="4" CellSpacing="1" Height="100%" GridLines="None" BackColor="#9CB6DB"
您将获得所需的结果。
答案 2 :(得分:0)
您可以通过RowDataBound事件更改它,如下所示:
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
// check if it's a data row (not header and footer)
if (e.Row.RowType == DataControlRowType.DataRow)
{
// take a color from a condition or not... i don't know what is your case
string color = condition ? "#ff9900" : "some-other-color";
// set the color on X column, where X is your column index (starting by 0)
e.Row.Cells[X].Attributes.Add("Style", "background-color: " + color + ";");
}
}
答案 3 :(得分:0)
简单使用网格视图的属性
<asp:GridView ID="grd_data" runat="server"
GridLines="Both" CssClass="gridline"></asp:GridView>
您还可以使用特定的水平和垂直
在样式表中创建一个css作为外部文件或内联
.gridline tr, .gridline td, .gridline th
{
border-top: 1px solid #DDDDDD;
border-bottom: 1px solid #DDDDDD;
border-left:1px solid #DDDDDD;
border-right:1px solid #DDDDDD;
}