Results 1 to 4 of 4

Thread: Set BGColor from VB Code Behind Based on sqlDatasources

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Set BGColor from VB Code Behind Based on sqlDatasources

    Can someone help me to set the bgcolor of an asp.net cell from code behind using a value from a sqldatasource?

    I have a working sql data source that is used to populate labels in my html form using asp.net.

    The background color of the cell depends on a comparison of the actual value versus the target value. If the actual daily value exceeds the limit I would like to change the bgcolor of a cell in the web page. The actual value comes from one datasource and the limit comes from a 2nd data source.

    In vb code behind I would like to accomplish the following pseudo code:

    If (sqlsource1Total > sqlsource2Limit) Then
    bgXCell.BgColor = "#ccff99"
    Else
    bgXCell.BgColor = "#ff9999"
    End If

    Can someone show an example of how to code this?

    Thank You

  2. #2
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Re: Set BGColor from VB Code Behind Based on sqlDatasources

    rowdatabound event

    http://stackoverflow.com/questions/4...alues-gridview

    Example:
    Code:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((Label)e.Row.Cells[0].FindControl("ValueHoldingControl").Text == "ABC")
            {
                //Coloring the cell
            }
        }
    }
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Set BGColor from VB Code Behind Based on sqlDatasources

    Hello egglebl,

    Welcome to the Forums!!

    Hopefully the above will help you, but I just wanted to say one thing...

    Although a SqlDataSource will get you up and running quite quickly, it is not referred to as a "Best Practice". Using this control closely couples your User Interface with your Database, and as such, should be avoided. The preference would be to use a segregated architecture, where your UI code is separate from your business logic, and your business logic separate from your database.

    Gary

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Re: Set BGColor from VB Code Behind Based on sqlDatasources

    Gary (GEP13) - Excellent point! Thank you for that suggestion, it makes perfect sense.

    Bryan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width