我在 GridView 中显示学生出勤率。
我选择缺席为A,出席为P,离开为L。现在我想用红色显示A,用绿色显示P。
怎么样。请帮助我
最佳答案
请试试这个,让我知道你遇到了什么问题
protected void grdStudent_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow dr = ((DataRowView)e.Row.DataItem).Row;
if (dr["Present"].ToString() == "A")
{
((Label)e.Row.FindControl("yourLableID")).ForeColor= System.Drawing.Color.Red;
//yourLableID is that lable in which you are showing A or P
}
}
}
关于c# - 不同颜色的gridview数据显示取决于文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2793215/