Solved

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

Posted on 2009-03-30
3
389 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 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