protected void RpSection_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
foreach (RepeaterItem item in RpSection.Controls)
{
if (item.FindControl("LblSection") is Label)
{
if (((Label)item.FindControl("LblSection")).Text == loginUser.Section)
{
((Label)item.FindControl("LblSection")).BackColor = System.Drawing.Color.Blue;
}
}
}
}
在这之前,我在if (item.FindControl("LblSection") is Label)语句之前还判断了一下: if(item.ItemType == ListItemType.Item)
这样的结构导致,偶数项还是获取不到。后来调试了下才发现,偶数项的ItemType是AlternatingItem类型的,这也是要注意的啦。