By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,797 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,797 IT Pros & Developers. It's quick & easy.

Alternating Item Style in a ListBox

P: n/a
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <ro****@hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP10.phx.gbl...

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2

P: n/a
Rob wrote:
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","backgrou nd-color: RED");
Next li

--

Riki

Nov 19 '05 #3

P: n/a
Rob

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #4

P: n/a
Rob

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.