在gridview中實(shí)現(xiàn)隔行樣式轉(zhuǎn)換的方法
在gridview中實(shí)現(xiàn)隔行樣式轉(zhuǎn)換的方法
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//我們先設(shè)置當(dāng)鼠標(biāo)上去的時候他的背景色改變
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ff6699'");
//下面我們再設(shè)置當(dāng)鼠標(biāo)離開后背景色再還原
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
/為特定的數(shù)改變行樣式這也是在這個事件里面,因?yàn)檫@個事件是在數(shù)據(jù)被綁定的時候執(zhí)行的
for (int i = 0; i < GridView1.Rows.Count; i++)
{
//為了對全部數(shù)據(jù)行都有用,我們使用循環(huán) //
string lbl = Convert.ToString(DataBinder.eval_r(e.Row.DataItem,"state"));
//我們得取出行中state字段綁定的值,用他作為判斷條件 //
if (lbl == "BB") if (e.Row.RowIndex % 2 == 1)
{
//如果他的值等于BB,那么
e.Row.BackColor = Color.LimeGreen;
//給當(dāng)前行的背景色賦值
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//我們先設(shè)置當(dāng)鼠標(biāo)上去的時候他的背景色改變
//下面我們再設(shè)置當(dāng)鼠標(biāo)離開后背景色再還原
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
/為特定的數(shù)改變行樣式這也是在這個事件里面,因?yàn)檫@個事件是在數(shù)據(jù)被綁定的時候執(zhí)行的
{
//為了對全部數(shù)據(jù)行都有用,我們使用循環(huán)
string lbl = Convert.ToString(DataBinder.eval_r(e.Row.DataItem,"state"));
//我們得取出行中state字段綁定的值,用他作為判斷條件
if (lbl == "BB")
{
//如果他的值等于BB,那么
e.Row.BackColor = Color.LimeGreen;
//給當(dāng)前行的背景色賦值
}
}
}