zoukankan      html  css  js  c++  java
  • 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 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

  • 相关阅读:
    测试代码运行效率
    用宏实现的单例模式
    上传控件的按钮改为图片
    ODAC的使用笔记
    ASP.NET防止重复提交
    向SharePoint图片库添加Item
    获取页面上用户控件的子控件ID
    SharePoint的WebService的应用
    GridView中HyperLinkField的链接使用JavaScript问题
    C#日期验证的正则表达式
  • 原文地址:https://www.cnblogs.com/emanlee/p/1739582.html
Copyright © 2011-2022 走看看