Solved

how do I change to row color every odd number row with repeater item?

Posted on 2009-03-30
3
392 Views
Last Modified: 2012-05-06
I need to change the rows bg color every odd color in a repeater item. any help would be appreciative.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        conn = New MySqlConnection(ConfigurationManager.AppSettings("MyConnectionString"))
        conn.Open()
 
        strSql = "Select * from login"
        cmd = New MySqlCommand(strSql, conn)
        da = New MySqlDataAdapter(cmd)
        ds = New DataSet()
        da.Fill(ds)
 
        Me.rptLogin.DataSource = ds.Tables(0)
        Me.rptLogin.DataBind()
 
        For Each item As RepeaterItem In rptLogin.Items
 
        Next
end sub

Open in new window

0
Comment
Question by:bschave2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
cdaly33 earned 500 total points
ID: 24021677
There is a template called AlternatingItemTemplate in Repeaters that you could use to set the background color.

Or... I'd try doing it in the repeaters item data bound event. See code.
  Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt.ItemDataBound
    If e.Item.ItemType = ListItemType.AlternatingItem Then
      DirectCast(e.Item.FindControl("Row"), HtmlTableRow).BgColor = "silver"
    End If
  End Sub

Open in new window

0
 

Author Comment

by:bschave2
ID: 24030261
how would I call this sub?
0
 

Author Comment

by:bschave2
ID: 24030311
getting this error: Object reference not set to an instance of an object.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question