Alternating Item Style in a ListBox

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Is there a way to set alternating item style for a ListBox? I know it
doesn't exist but is there a way to mimmick the Datagrid's
AlternatingItemStyle?

Thanks
Rob
 
If (e.Item.ItemType = ListItemType.AlternatingItem) Then
....set whatever style you want to
End If




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================
 
Rob said:
Is there a way to set alternating item style for a ListBox? I know it
doesn't exist but is there a way to mimmick the Datagrid's
AlternatingItemStyle?

Here's a piece of code that does what you want (VB.NET):

Dim i As Integer
For i=0 To Listbox1.Items.Count-1 Step 2
ListBox1.Items(i).Attributes.Add("style","background-color: RED");
Next li
 
Thanks Riki...but it doesn't seem to be working. I tried this before and
it didn't work so I thought it wasn't possible. I tried it again and it
still doesn't work. Does this code look OK to you?


'I've already populated the dataset at this point.

lstCompanies.DataSource = ds
lstCompanies.DataTextField = "fullname"
lstCompanies.DataValueField = "company_id"
lstCompanies.DataBind()

lstCompanies.Items.Insert(0, New ListItem("--Select a buyer from the
list--"))

Dim i As Integer
For i = 0 To lstCompanies.Items.Count - 1 Step 2
lstCompanies.Items(i).Attributes.Add("style", "background-color: red")
Next

Rob
 
Back
Top