Solved

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

Posted on 2009-03-30
3
382 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
Comment Utility
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
Comment Utility
how would I call this sub?
0
 

Author Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now