GridView绑定时通过RowDataBound事件获取数据源列值
/// <summary>
/// 当数据绑定时, 设置未读邮件加粗显示
/// </summary>
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
//if (DataBinder.Eval(e.Row.NamingContainer, "DataRow.Readed").ToString() == "0")
//if (gvData.DataKeys[e.Row.RowIndex][1].ToString() == "0")
DataRowView drv = (DataRowView)e.Row.DataItem;
if (drv != null)
{
if (drv.Row["Readed"].ToString() == "0")
e.Row.Style["font-weight"] = "bold";
}
}
要引入命名空间:
using System.Data;
当看到一些不好的代码时,会发现我还算优秀;当看到优秀的代码时,也才意识到持续学习的重要!--buguge
本文来自博客园,转载请注明原文链接:https://www.cnblogs.com/buguge/archive/2012/04/05/2433494.html