我有一个数据限制的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中它确实..