日期:2014-05-18 浏览次数:20435 次
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 112px" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateColumn> <ItemTemplate> <table width="2100" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" style="font-family:Arial, Helvetica, sans-serif;font-size:13px;"> <tr> <td width="52"><%# DataBinder.Eval(Container, "DataItem.Name") %></td> <td width="52"><%# DataBinder.Eval(Container, "DataItem.Age") %></td> </tr> </table> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid>
public string GetAge(object o){ return Convert.ToInt32(o) > 20 ? "<font color='red'>"+o.ToString()+"</font>" : o.ToString(); }
------解决方案--------------------
/// <summary> /// 绑定数据时发生事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GridViewDetails_RowDataBound(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) { case DataControlRowType.Header: break; case DataControlRowType.Footer: break; case DataControlRowType.DataRow: TableCell tc = e.Row.Cells[11]; if (tc.Text.Trim() != "" && tc.Text.Trim() != " ") { tc.Attributes.Add("style", int.Parse(tc.Text.Trim()) > 0 ? "color:#FF0000" : "color:#458B00"); } break; default: break; } }