8 Answers, 1 is accepted
This is a kinda simple example which populates a combo with ten items, but it provides a new backcolor for even rows:
| protected void MakeCombo_Click(object sender, EventArgs e) |
| { |
| for (int x = 0; x < 10; x++) |
| { |
| RadComboBoxItem rcbi = new RadComboBoxItem(); |
| rcbi.Text = "Item " + x.ToString(); |
| rcbi.Value = "Item" + x.ToString(); |
| if (x % 2 == 0) |
| rcbi.BackColor = Color.LightGray; |
| RadCombo1.Items.Add(rcbi); |
| } |
| } |
In theory you could use the same kinda logic after it's been databound (i.e., foreach RadComboItem b in RadCombo1.Items), just using it's position in the list to add a little color.
RadComboBox does not have built-in support for alternating items in the skins.
All the best,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
| <telerik:RadComboBox ID="RadComboBox1" |
| runat="server" |
| ondatabound="RadComboBox1_DataBound"> |
| </telerik:RadComboBox> |
| protected void RadComboBox1_DataBound(object sender, EventArgs e) |
| { |
| foreach (RadComboBoxItem rcbi in RadComboBox1.Items) |
| { |
| if (rcbi.Index % 2 == 0) |
| rcbi.CssClass = "comboBoxListItem"; |
| else |
| rcbi.CssClass = "alternatingComboBoxListItem"; |
| } |
| } |
| .comboBoxListItem |
| { |
| background-color: #C9F1FA; |
| } |
| .alternatingComboBoxListItem |
| { |
| background-color: #FFF; |
| } |
If e.Item.Index Mod 2 = 0 Then
e.Item.CssClass = "comboBoxListItem"
Else
e.Item.CssClass = "alternatingComboBoxListItem"
End If
I have successfully used Guy's example on a statically created RadComboBox but am struggling to do the same for a dynamically created one. I have successfully added an event handler for the SelectedIndexChanged event but I am struggling with adding one to the ItemDataBound event.
When I create the RadComboBox dynamically I add a handler for the SelectedIndexChanged event like this
AddHandler MyRadComboBox(intRow).SelectedIndexChanged, AddressOf MyRadComboBoxSelectedIndexChanged
Private Sub MyRadComboBoxSelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)So for the ItemDataBound event I feel I should add the handler like this:
AddHandler MyRadComboBox(intRow).ItemDataBound, AddressOf MyRadComboBoxItemDataBoundAlternateShadingand create a sub like this:
Private Sub MyRadComboBoxItemDataBoundAlternateShading(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBox????????) If e.Index Mod 2 = 0 Then
e.CssClass = "RadComboBoxListItem"
Else
e.CssClass = "RadComboBoxListItemAlternate"
End If
End Sub
But I can't find the desired event (the question marks).
Do I need a different approach for this?
The event arguments type is RadComboBoxItemEventArgs, as specified in the ItemDataBound help article.
Regards,
Dimitar
Telerik
See What's Next in App Development. Register for TelerikNEXT.