我正在从sql server显示Gridview中的学生出勤率。我选择apsent作为A,作为P出现并保留为L.现在我想在Gridview数据绑定中显示红色的A,绿色的P,而不是标题文本。如何。请帮帮我
答案 0 :(得分:1)
<asp:GridView ID="studentGridView" runat="server" OnRowDataBound="studentGridView_RowDataBound"/>
protected void studentGridView_RowDataBound(Object sender,GridViewRowEventArgs e)
{
const int statusFieldIndex = 1;
if (e.Row.Cells[statusFieldIndex].Text == "A")
{
e.Row.BackColor = Color.Red;
}
//etc
}
statusFieldIndex将设置为包含A,L,P等的字段的索引