asp .net Gridview改变垂直线的颜色

问题描述 投票:3回答:4

我试图改变asp.net网格视图的水平和垂直线的颜色。我正在更改单元格边框颜色,但只更改了水平线。你可以看到附图。

asp.net
4个回答
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
投票

只需删除所有边框并执行以下操作,在网格视图标记中添加以下代码行。

CellPadding="4" CellSpacing="1" Height="100%" GridLines="None" BackColor="#9CB6DB"

您将获得所需的结果。


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 + ";");
    }
}

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;
} 
© www.soinside.com 2019 - 2024. All rights reserved.