Click here to Skip to main content
15,886,258 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..
Posted
Comments
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:
XML
<asp:GridView runat="server" ID="grd">
           <Columns>
               <asp:TemplateField HeaderText="Header1">
                   <ItemTemplate>
                       <asp:Label runat="server" ID="lbl" CssClass='<%#Eval("cl") %>' Width="100%" Text='<%#Eval("ID") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>


Then Write Style Sheet like This:
XML
<style type="text/css">
        .R
        {
            background-color: Red;
        }
        .Y
        {
            background-color: Black;
        }
    </style>
 
Share this answer
 
v2

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