2

我有一个数据有界的gridview。我希望每次绑定数据时,某些行的边框颜色和宽度都会改变。我写了这个函数:

protected void GridView1_DataBound(object sender, EventArgs e)
{   
    int column = 3;
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        string current = GridView1.Rows[i].Cells[column].Text;
        string next;
        if (i+1 < GridView1.Rows.Count) next = GridView1.Rows[i + 1].Cells[column].Text;
        else return;

        if (current != next)
        {
            GridView1.Rows[i + 1].Style[HtmlTextWriterStyle.BackgroundColor] = "#FFFF00";

            GridView1.Rows[i + 1].Style.Add(HtmlTextWriterStyle.BorderWidth, "20px");
            GridView1.Rows[i + 1].Parent.
            GridView1.Rows[i + 1].Style.Add(HtmlTextWriterStyle.BorderColor, "#000000");

        }
    }

}

问题是背景颜色有效,但边框没有..我怎样才能给行边框宽度和颜色?

谢谢 :-)

我自己解决了:

    protected void GridView1_DataBound(object sender, EventArgs e)
{           
    int column = 3;
    string current;
    string next;
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        current = GridView1.Rows[i].Cells[column].Text;
        if (i+1 < GridView1.Rows.Count) next = GridView1.Rows[i + 1].Cells[column].Text;
        else return;

        if (current != next)
        {
            //GridView1.Rows[i + 1].Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFF200");
            GridView1.Rows[i].Attributes["style"] = "border-top-style:none; border-bottom-style:solid; border-left-style:none; border-right-style:none; border-color:Black;";
        }
    }     
}

但它不适用于 IE,在 chrome 中它可以..

4

0 回答 0