回发后列表框丢失样式的项目

时间:2014-04-10 11:33:09

标签: asp.net vb.net

我有一个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的项目丢失了样式

0 个答案:

没有答案