int the itemdatabind()
if(var1="合租")
e.Item.Cells(1).ForeColor=Color.Red;
else if(var1="出租")
......
else
........

解决方案 »

  1.   

    在Page_Load中,遍历datagrid,动态设置颜色
      

  2.   

    在DataGrid的ItemDataBound事件的方法中判断并设置其Fore-Color
      

  3.   

    Change Color of a Column Based on Column Values
    http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp
      

  4.   

    <asp:datagrid  id="" ....>
    <Columns>
    <asp:TemplateColumn HeaderText="租售类型">
    <ItemTemplate>
    <font color ='<%# get_color(databinder.eval(Container.DataItem,"type")) %>'>
    <%# databinder.eval(Container.DataItem,"type") %>
    </font>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    Function get_color(ByVal mytype)
        Dim aa As String
        Select Case mytype
            Case "出租"
                aa = "red"
    Case "求购"
                aa = "blue"
            Case Else
                aa = "yellow"
        End Select
        Return aa
    End Function