Click here to Skip to main content
14,733,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table with some columns as name class status..
in grid view in am fetching the values from the table..
i want if the status is no then row color = red else yellow..
Sinisa Hajnal 10-Dec-14 4:22am
What have you tried? Did you even try to search for the solution? This is something easily found.

1 solution

if u get the data from database query then u should write query like 'select columns,case when status='on' then 'R' else 'Y' end as cl from tbl'.. then bind the grid..

then in gridview write item template like this:
<asp:GridView runat="server" ID="grd">
               <asp:TemplateField HeaderText="Header1">
                       <asp:Label runat="server" ID="lbl" CssClass='<%#Eval("cl") %>' Width="100%" Text='<%#Eval("ID") %>'></asp:Label>

Then Write Style Sheet like This:
<style type="text/css">
            background-color: Red;
            background-color: Black;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900