title: how to have listview row colour to change based on data in the row
body: <p>I followed this question <a href="https://stackoverflow.com/q/5440225/447362">stuck on changing each row color during run-time in listview in asp.net based on database entries</a>  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 =><br>
  Dim cell As HtmlTableRow = DirectCast(e.Item.FindControl("MainTableRow"), mlTableRow)</p>
  
  <p>Please let me know if there is any better way / correct way to do this in VB?</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Many thanks for your help.</p>
  
  <p>dk</p>