Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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