V
Vincent
Hi,
the dropdownlist is fed by code-behind with property 'autopostback'="true".
What i want is to put a color to the items of the dropdownlist. I tried two
ways: with Attributes.Add("style", "color:red") and with
DropDownList1.ForeColor.
EnabledViewState is set to "true".
The first way doesn't work: the first time, the items in the dd are red, but
at the first postback, the red color has gone.
The second way works: the items in the dd are red and remains red after the
next postbacks.
This is the aspx-code:
<%@ Page Language="VB" ... EnabledViewState="true" %@>
<aspropDownList id="DropDownList1" runat="server" AutoPostBack="true">
</aspropDownList>
code-behind:
first way: this doesn't work
---------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
........
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
else
For i = 1 To 10
z = New ListItem(i, i)
z.Attributes.Add("style", "color:red")
DropDownList1.Items.Add(z)
next
end if
.........
second way: this works
------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
.....
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
Else
For i = 1 To 10
z = New ListItem(i, i)
DropDownList1.ForeColor = Drawing.Color.Red
DropDownList1.Items.Add(z)
next
end if
.........
Why does the first way not work?
Meanwhile I found a solution:
-----------------------------
.....
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
DropDownList1.Items.Clear()
End If
For i = 1 To 10
z = New ListItem(i, i)
z.Attributes.Add("style", "color:red")
DropDownList1.Items.Add(z)
next
But still want to know why first way doesn't work.
Thanks
Vincent.
the dropdownlist is fed by code-behind with property 'autopostback'="true".
What i want is to put a color to the items of the dropdownlist. I tried two
ways: with Attributes.Add("style", "color:red") and with
DropDownList1.ForeColor.
EnabledViewState is set to "true".
The first way doesn't work: the first time, the items in the dd are red, but
at the first postback, the red color has gone.
The second way works: the items in the dd are red and remains red after the
next postbacks.
This is the aspx-code:
<%@ Page Language="VB" ... EnabledViewState="true" %@>
<aspropDownList id="DropDownList1" runat="server" AutoPostBack="true">
</aspropDownList>
code-behind:
first way: this doesn't work
---------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
........
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
else
For i = 1 To 10
z = New ListItem(i, i)
z.Attributes.Add("style", "color:red")
DropDownList1.Items.Add(z)
next
end if
.........
second way: this works
------------------------
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
.....
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
Else
For i = 1 To 10
z = New ListItem(i, i)
DropDownList1.ForeColor = Drawing.Color.Red
DropDownList1.Items.Add(z)
next
end if
.........
Why does the first way not work?
Meanwhile I found a solution:
-----------------------------
.....
If Page.IsPostBack Then
dd = DropDownList1.SelectedValue
DropDownList1.Items.Clear()
End If
For i = 1 To 10
z = New ListItem(i, i)
z.Attributes.Add("style", "color:red")
DropDownList1.Items.Add(z)
next
But still want to know why first way doesn't work.
Thanks
Vincent.