datagrid的问题,默认的摸板是一行交替一行换色,但是我希望的是
datagrid的问题,默认的摸板是一行交替一行换色,但是我希望的是前X行是红色,接着X行是蓝色,再X行是红色???如何做啊
------解决方案--------------------protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.ItemIndex % 4 == 0 || e.Item.ItemIndex % 4 == 1)
{
e.Item.Style[ "Color "] = "red ";
}
else
{
e.Item.Style[ "Color "] = "blue ";
}
}
}
------解决方案--------------------protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// 每 4 行
e.Item.Style[ "background-color "] = ((((e.Item.ItemIndex+1)/4)%2) == 0) ? "red " : "blue ";
}
}