VS2005中某列换颜色的总结
前台对应第5列
<asp:BoundField DataField="Md_Status1" HeaderText="状态">
<ItemStyle CssClass="item" HorizontalAlign="Center" Width="80px" />
</asp:BoundField>
后台
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(e.Row.Cells[4].Text=="未回复")//如果是模板列不能这么用
{
e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
}
}
}
2.模板列
<asp:TemplateField HeaderText="aa">
<ItemStyle/>
<ItemTemplate>
<%# pay(Eval("aa").ToString())%>
</ItemTemplate>
</asp:TemplateField>
后台调用
public string pay(string str)
{
if (str == "1")
{
return "<font color='red'> bb</font>";
}
else
{
return "cc";
}
}