我有一个ListBox。当我绑定数据时,我需要通过颜色区分一些项目。我是怎么做的
Protected Sub ListBox_DataBound(ByVal sender As Object, ByVal e As EventArgs)
Dim lb As ListBox = CType(sender, ListBox)
For Each li As ListItem In lb.Items
If someFlag = True Then
li.Attributes("style") += "color: red;"
End If
Next
End Sub
但是当我做回发时,这些风格就丢失了。如何在回发之间保存风格? 编辑:内页Page_Load我对此列表框没有任何操作。我在ddl发生事件selectIndexChange时填充列表框。但是当我点击linkbutton
时Private Sub lnkbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkBtn.Click
Dim selectedItems As ArrayList = New ArrayList
For Each itm As ListItem In listbox1.Items
If itm.Selected = True Then
selectedItems.Add(itm)
End If
Next
For i As Int32 = 0 To selectedItems.Count - 1
listbox1.Items.Remove(selectedItems(i))
listbox2.Items.Add(selectedItems(i))
Next
End Sub
此事件后listbox1的项目丢失了样式