网格视图中不同颜色的数据显示取决于asp.net中的文本
我正在从sql server在Gridview中显示学生出勤情况。我选择apsent作为A,present作为P,leave作为L。现在我想在Gridview数据绑定中显示A为红色,P为绿色,而不是标题文本。怎么样。请帮帮我网格视图中不同颜色的数据显示取决于asp.net中的文本,asp.net,Asp.net,我正在从sql server在Gridview中显示学生出勤情况。我选择apsent作为A,present作为P,leave作为L。现在我想在Gridview数据绑定中显示A为红色,P为绿色,而不是标题文本。怎么样。请帮帮我 <asp:GridView ID="studentGridView" runat="server" OnRowDataBound="studentGridView_RowDataBound"/> protected void studentGridVi
<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
}
受保护的void studentGridView_RowDataBound(对象发送方,GridViewRowEventArgs e)
{
const int statusFieldIndex=1;
if(e.Row.Cells[statusFieldIndex].Text==“A”)
{
e、 Row.BackColor=Color.Red;
}
//等
}
statusFieldIndex将设置为包含A、L、p等的字段的索引受保护的无效studentGridView_RowDataBound(对象发送方,GridViewRowEventArgs e){const int statusFieldIndex=1;if(e.Row.Cells[statusFieldIndex].Text=“A”){e.Row.BackColor=Color.Red;}//etc}如果此文本中的(e.Row.Cells[statusFieldIndex].Text==“A”)与列标题文本进行比较,则statusFieldIndex将设置为包含A、L、P等的字段的索引。但我想比较本文中的绑定数据(A)(e.Row.Cells[statusFieldIndex].Text==“A”)与列标题文本。但是我想比较绑定数据(A)–e.Row.DataItem包含源数据