Click here to Skip to main content
14,667,959 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100