Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:07:03+00:00 2026-06-08T22:07:03+00:00

So I have connected a grid to a database where my database contains values

  • 0

So I have connected a grid to a database where my database contains values of only 1, 2, and 3. I want to have it so that every box that has a 1 is green, 2 is yellow, and 3 is red.

My questions is where should i put the conditioning code and what language should i do it in?

The following information is just my gridview and the data i am linking it to.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDataSource1"
    >
    <Columns>
        <asp:BoundField DataField="Line" HeaderText="Line"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" ItemStyle-BackColor="#FF6699" />
        <asp:BoundField DataField="Jan" HeaderText="Jan"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Feb" HeaderText="Feb"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Mar" HeaderText="Mar"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Apr" HeaderText="Apr"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="May" HeaderText="May"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Jun" HeaderText="Jun"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Jul" HeaderText="Jul"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Aug" HeaderText="Aug"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Sep" HeaderText="Sep"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Oct" HeaderText="Oct"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Nov" HeaderText="Nov"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="Dec" HeaderText="Dec"  ItemStyle-Width="75" ItemStyle-HorizontalAlign="Right" />

    </Columns>
</asp:GridView>



<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:dashboardConnectionString %>" 
SelectCommand="SELECT 
        line AS Line, 
        [2012-01-31] AS 'Jan', 
        [2012-02-29] AS 'Feb', 
        [2012-03-31] AS 'Mar', 
        [2012-04-30] AS 'Apr', 
        [2012-05-31] AS 'May', 
        [2012-06-30] AS 'Jun', 
        [2012-07-31] AS 'Jul', 
        [2012-08-31] AS 'Aug', 
        [2012-09-30] AS 'Sep', 
        [2012-10-31] AS 'Oct', 
        [2012-11-30] AS 'Nov', 
        [2012-12-31] AS 'Dec'
    FROM
    (Select line, report_month, state FROM [Monthly_State]) AS sourcetable
    PIVOT
    (
    MAX(state) 
    FOR report_month IN ([2012-01-31], [2012-02-29], [2012-03-31], [2012-04-30], [2012-05-31], [2012-06-30], [2012-07-31], [2012-08-31], [2012-09-30], [2012-10-31], [2012-11-30], [2012-12-31])
    ) as pivottable; ">

    </asp:SqlDataSource>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:07:05+00:00Added an answer on June 8, 2026 at 10:07 pm

    I would do it by using template field and declare a public method in code behind as follows

    <asp:TemplateField>
    <ItemTemplate>
    <asp:Label ID="cddasf" runat="server" CssClass='<%# GetClass(Eval("colum name")) %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    In the code behind

    public  string GetClass(object g)
    {
    

    // process the value and return the css class name you want

    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TabPanel which contains, among other things, a Grid connected to a Store.
I have connected to a table of the database and found a row by
I have connected to local and server database from local SqlServer 2005. How to
I have connected with the database successfully by using wizard in server explorer. but
I have a mp3 Player. I have connected it to my PC which has
I have never connected to a database in java before. May I know if
I have a few 1000s triangles connected in a 2D mesh grid. It represents
I have a collection ItemDemandCollection which is connected to a data grid. If a
I have a Delphi application using DevExpress cxGrid (which is connected to database). I
I have a list of objects arranged on a grid. I want to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.