After page postback, DropDownList item attributes "color" cleared ?
  TnD0WQEygW8e 2023年11月15日 48 0

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 information 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



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月15日 0

暂无评论

推荐阅读
  rvP2pqm8fEoB   2023年12月24日   37   0   0 ListJavaListJava
TnD0WQEygW8e