GridView通过RowDataBound事件获取字段值、数据源列值

如果数据源有某一列,而在绑定到GridView时不显示该列,编程时要用到该列的值可以用以下方法:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView dr = (DataRowView)e.Row.DataItem;
            if (dr["btype"].ToString() == "1")
                e.Row.ForeColor = System.Drawing.Color.Red;
        }
    }

 

你可能感兴趣的:(GridView)