微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

After page postback, DropDownList item attributes "color" cleared ?

DropDownList1.SelectedItem.Attributes.Add("style", "Color:GREEN")
This is set when a person clicks a button, "resubmit order"... then the selected item is turned green so they kNow they've already fixed that order item.
Now if I select a different item, the page posts back to grab new @R_441_4045@ion for another order...., but the prevIoUsly set dropdownlist item, is no longer green.
I'm not refilling the dropdown, if the postback=true, so I have no idea why the viewstate is not keeping the attributes of the dropdown list items.
How can I preserve the color of dropdownlist items, after a postback ?

----------------------

Try this:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    For Each index As Integer In Me.SelectedItems
        DropDownList1.Items(index).Attributes.Add("style", "Color:GREEN;background:red")
    Next
End Sub


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'DropDownList1.SelectedItem.Attributes.Add("style", "Color:GREEN");
    Dim selecteditems As List(Of Integer) = Me.SelectedItems
    selecteditems.Add(DropDownList1.Selectedindex)
    Me.SelectedItems = selecteditems
End Sub


Private _SelectedItems As List(Of Integer)
Public Property SelectedItems() As List(Of Integer)
    Get
        If ViewState("SelectedItems") IsNot nothing Then
            _SelectedItems = DirectCast(ViewState("SelectedItems"), List(Of Integer))
        Else
            _SelectedItems = New List(Of Integer)()
        End If
        Return _SelectedItems
    End Get
    Set(ByVal value As List(Of Integer))
        ViewState("SelectedItems") = value
    End Set
End Property

 

http://forums.asp.net/p/1159612/1913450.aspx

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_25339597.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐