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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:42:22+00:00 2026-05-21T22:42:22+00:00

I followed this question stuck on changing each row color during run-time in listview

  • 0

I followed this question stuck on changing each row color during run-time in listview in asp.net based on database entries and tried to do the same in VB but i am getting some unexplained errors, like Object reference not set to an instance of an object
most likely for this row =>
Dim cell As HtmlTableRow = DirectCast(e.Item.FindControl(“MainTableRow”), mlTableRow)

Please let me know if there is any better way / correct way to do this in VB?

Protected Sub ListView2_ItemDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) _
Handles ListView2.ItemDataBound
    If e.Item.ItemType = ListViewItemType.DataItem Then
        Dim dataitem As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)
        Dim mstorename As String = DataBinder.Eval(dataitem.DataItem, "Store")
        If mstorename = "A1" Then
            Dim cell As HtmlTableRow = DirectCast(e.Item.FindControl("MainTableRow"), mlTableRow)
            cell.BgColor = #E0E0E0
        End If
    End If
End Sub

Many thanks for your help.

dk

  • 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-05-21T22:42:23+00:00Added an answer on May 21, 2026 at 10:42 pm

    For this to work, you must ensure that you provide MainTableRow id to tr element and mark it as runat="server" i.e. make sure that your mark-up (html) is something like

    <ItemTemplate>
       <tr id="MainTableRow" runat="server">
       ...
    

    A different (and IMO, simpler) approach will be using data-binding expressions. For example, in your markup, use

    <ItemTemplate>
           <tr class='<%# GetRowStyle(Container.DataItem) #>'>
    

    And in code-behind, have a protected function to provide CSS class based on data (a example c# function will be)

    protected string GetRowStyle(object item)
    {
       var store = DataBinder.Eval(item, "Store");
       if (store == "A1")
       {
          return "altRow";
       }
       else
       {
         return "row";
       }
    }
    

    And lastly, define those css classes (row, altRow) as per your needs.

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

Sidebar

Related Questions

Followed this question about delayed_job and monit Its working on my development machine. But
I've followed instructions from this question on SO to set up RVM, rubies and
I have followed the suggestion in this question... [ How to handle checkboxes in
I have followed the suggestion in this question as I am using Django, I
I thought I had correctly followed the recommendations in this question for checking undefined
After this question , I need to know what principles should be followed in
Ok, sorry if this question is stupid. I followed this tutorial: http://www.youtube.com/watch?v=E30_-pQGQXs . Now
I followed this tutorial and successfully installed Emacs, STk, Quack. The question is how
This question stems from this question that I asked yesterday. I've followed Theo's advice
This question is related to this previous thread . I followed Tomas's suggestion using

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.