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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:58:49+00:00 2026-06-03T20:58:49+00:00

I tried my best to shrink down the program to the following code. In

  • 0

I tried my best to shrink down the program to the following code. In this example, I have UK and USA as valid countries. If someone lives outside those countries, I wanna show an error message and highlight them on the gridview. For example, John and Chris are from China so they should be highlighted on the gridview. Is it possible to do that ? Please see example picture. Either just Name or the whole row can be highlighted.

Thanks a lot.

    Dim dt As New DataTable
    dt.Columns.Add("ID")
    dt.Columns.Add("Name")
    dt.Columns.Add("Country")

    dt.Rows.Add("1", "John", "China")
    dt.Rows.Add("2", "Harry", "USA")
    dt.Rows.Add("3", "Joe", "UK")
    dt.Rows.Add("4", "Emma", "UK")
    dt.Rows.Add("5", "Chris", "China")
    dt.Rows.Add("6", "Jenny", "UK")


    Dim isValid As Boolean = True
    Dim keywords() As String = {"UK", "USA"}
    Dim str As String = ""

    For Each x As DataRow In dt.Rows
        If Not keywords.Contains(x("Country").ToString()) = True Then
            isValid = False
        End If
    Next

    If isValid = False Then
        lblmessage.Text = "Some people don't live in valid countries"
    End If

    GridView1.DataSource = dt
    GridView1.DataBind()

enter image description here

  • 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-03T20:58:52+00:00Added an answer on June 3, 2026 at 8:58 pm

    Is it possible to do that ?

    Yes, one way is to use GridView’s RowDataBound event. Assuming you have a list of valid countries:

    Private validCountries() As String = {"UK", "USA"}
    
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Select Case e.Row.RowType
            Case DataControlRowType.DataRow
                Dim row = DirectCast(e.Row.DataItem, DataRowView).Row
                Dim country = row.Field(Of String)("Country")
                ' assuming you're using TemplateFields with LblName for the Name of the user '
                Dim LblName = DirectCast(e.Row.FindControl("LblName"), Label)
                If Not validCountries.Contains(country.ToUpper) Then
                    LblName.CssClass = "InvalidCountry"
                End If
        End Select
    End Sub
    

    If you’re using BoundFields instead, you need to apply the CSS on the table cell

    e.Row.Cells(1).CssClass = "InvalidCountry"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried my best to solve this but i cannot figure this out.
I have tried my best to answer this question myself through research but I
Warning: This question has been heavily edited. I tried my best to guess the
I have tried my best to understand the page translation concept shown here Offset
Getting this Problem. Tried my best, I looked up some stuff and they said
I know this question might sound quite stupid, but I've tried my best and
I tried to summarize the this as best as possible in the title. I
Im quite stuck here and I have tried my best but I could not
I've been stuck on this problem for a while now and have tried my
This is one of those hard to explain questions. I've tried my best below,

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.