I have a CheckBoxListItem listing all 50 states. I'm pulling out satet information from a sql db. I can get the data jsut fine, but what I want to do is change the color of the accompanying label if that state exists in the dataset. Is this possible?
Sure it is just loop through the dataset using a for loop and check to see if the two strings match if they do then set your label.backcolor to the color you want. That'l do donkey, that'l do
yeah i'm already looping through the checkboxlist.items(x), the thing is that i can't call out the label object for the checkboxlist item, to do anything to it.
here's my sub:
Private Sub checkItems(ByVal theCheck As CheckBoxList, ByVal compAr As Array)
Dim i, x As Integer
Dim chkStr, valStr As String
For i = 0 To (theCheck.Items.Count - 1)
chkStr = Trim(theCheck.Items(i).Text)
For x = 0 To UBound(compAr)
valStr = Trim(CStr(compAr(x)))
If chkStr = valStr Then
theCheck.Items(i).Selected = True
End If
Next
Next
End Sub
At the same time i'm setting the "selected = true", i want to change the label text color.
Ok I am thinking this is harder than I thought. Agg to much thinking.
Sorry
There isn't a forecolor attribute per item basis. However I do have good news. There is an attribute collection for each item. You could try to play with this since I haven't worked with attribute collections to date I chose a different route. Change the text of the desired item to include basic html in it. Such as this. I have turned all non selected items to have italicised text.
dim i as integer
For i = 0 To (CheckBoxList1.Items.Count - 1)
If Not CheckBoxList1.Items(i).Selected Then
CheckBoxList1.Items(i).Text = "<i>" & CheckBoxList1.Items(i).Text & "</i>"
End If
Next
That should work splendidly That'l do donkey, that'l do
yeah i tried the changing text to include html method. it kinda works. the thing is that it won't change the text back, when i unselect the item and re-post.
i know it should be good enough that i'm doing the "selected = true", but the end user is not so "savvy" so i'd like to be able to give him/her another visual clue that their selection was applied.
Just add one these event handlers for the itemchanged event
Private Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged
End Sub
Inside the event handler you'll need to do some string manipulation to get the original value.
The other option would be to rebind the control so that the original values from the database are shown. That'l do donkey, that'l do
the thing is i don't need the change to happen when the item is clicked, i need it to change after the list of items has been bound to the ds, and then the item comparison is made.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.