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 8582155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:13:26+00:00 2026-06-11T21:13:26+00:00

I need to loop thru particualr columns in a gridview. For example, I need

  • 0

I need to loop thru particualr columns in a gridview. For example, I need to loop every “%” columns and then assign colors according to their values, is there a simple way to achieve it? Thanks.

Gridview table
enter image description here

RowDataBound event

    Protected Sub gv_ssi_rzli_data_1_RowDataBound(sender As Object, e As EventArgs) Handles gv_ssi_rzli_data_1.RowDataBound

    Dim gv As GridView = gv_ssi_rzli_data_1

    For i As Integer = 0 To gv.Rows.Count - 1

        If gv.Rows(i).Cells(0).Text = "Oct" Or
            gv.Rows(i).Cells(0).Text = "Nov" Or
            gv.Rows(i).Cells(0).Text = "Dec" Then

            If gv.Rows(i).Cells(2).Text >= Session("rzli_avg_blue_1") Then
                gv.Rows(i).Cells(2).BackColor = System.Drawing.Color.LightBlue
            ElseIf gv.Rows(i).Cells(2).Text >= Session("rzli_avg_green_1") And gv.Rows(i).Cells(2).Text < Session("rzli_avg_blue_1") Then
                gv.Rows(i).Cells(2).BackColor = System.Drawing.Color.LightGreen
            ElseIf gv.Rows(i).Cells(2).Text >= Session("rzli_avg_yellow_1") And gv.Rows(i).Cells(2).Text < Session("rzli_avg_green_1") Then
                gv.Rows(i).Cells(2).BackColor = System.Drawing.Color.LightYellow
            ElseIf gv.Rows(i).Cells(2).Text <= Session("rzli_avg_red_1") Then
                gv.Rows(i).Cells(2).BackColor = System.Drawing.Color.LightPink
            End If


        End If


    Next

End Sub
  • 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-11T21:13:27+00:00Added an answer on June 11, 2026 at 9:13 pm

    There are a number of ways to do this.

    First, I should probably point out that you seem to be reading through the entire grid every time you bind a row, which seems unnecessary.

    That aside, perhaps the simplest way would to be abstract the code that does the comparison to your value ranges into its own method, with the parameters to be the cell to be tested and modified. Since I assume from your use of the column index 2 that you know what columns are percentage columns, you would just call your new method with the relevant cell, like so:

    For i As Integer = 0 To gv.Rows.Count - 1
        Dim row = gv.Rows(i)
    
        Dim rowHeaderCell = row.Cells(0)
        if rowHeadercell.Text = "Oct" Or 
           rowHeaderCell.Text = "Nov" or 
           rowHeaderCell.Text = "Dec" Then
    
           SetCellBackGround(row.Cells(2))
           SetCellBackground(row.Cells(4))
           ' etc.
        End If
    Next
    

    I assume, above, that for whatever reason you want just to highlight Oct-Dec numbers. If you want that to vary, or want to use a different set of colors for other quarters, please say so.

    SetCellBackground would look like this (typed from memory):

    Sub SetCellBackground(TableCell cell) 
    
        If cell.Text >= Session("rzli_avg_blue_1") Then
                cell.BackColor = System.Drawing.Color.LightBlue
            ElseIf cell.Text >= Session("rzli_avg_green_1") And cell.Text < Session("rzli_avg_blue_1") Then
                cell.BackColor = System.Drawing.Color.LightGreen
            ElseIf cell.Text >= Session("rzli_avg_yellow_1") And cell < Session("rzli_avg_green_1") Then
                cell = System.Drawing.Color.LightYellow
            ElseIf cell <= Session("rzli_avg_red_1") Then
                cell.BackColor = System.Drawing.Color.LightPink
            End If
    
     End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to loop every row of a dataset 100k times. This dataset contains
I need to loop through all table elements, somewhere keeping an index and then
I'm using Core Data and I need to loop thru the result of the
I need to loop a const char , and I've used a simple example
I need to Loop my FormCollection to get Id values from collection.. I have
I need to loop through a List of Dictionaries List<Dictionary<string,string>> to populate a DataTable.
I need to loop through a set of 2-dimensional array of hidden input fields
I need to loop over a query exactly 12 times to complete rows in
I need to loop through each day of the week (monday tues...) and compare
i have the following code ..i need to loop through end of the file

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.