Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a DropDownList who's function is to change its color depending on the scores selected. here are the codes:

XML
<asp:DropDownList AutoPostBack="true" ID="rating1"  runat="server" Width="60px"
                      onselectedindexchanged="rating1_SelectedIndexChanged">
                      <asp:ListItem>NA</asp:ListItem>
                      <asp:ListItem>1</asp:ListItem>
                      <asp:ListItem>1.5</asp:ListItem>
                      <asp:ListItem>2</asp:ListItem>
                      <asp:ListItem>2.5</asp:ListItem>
                      <asp:ListItem>3</asp:ListItem>
                      <asp:ListItem>3.5</asp:ListItem>
                      <asp:ListItem>4</asp:ListItem>
                      <asp:ListItem>4.5</asp:ListItem>
                      <asp:ListItem>5</asp:ListItem>
                  </asp:DropDownList>



event:

C#
protected void rating1_SelectedIndexChanged(object sender, EventArgs e)
  {
      float value = float.Parse(rating1.Text);
      if (value <= 3)
      {
          rating1.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFF66");
      }
      else
      {
          rating1.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF3300");
      }
  }


how can this event fire after selecting the scores from dropdown list??
Posted
Updated 5-Nov-13 15:42pm
v2
Comments
walterhevedeich 5-Nov-13 22:12pm    
What version of ASP.Net? If this is an old one, I am thinking you also need to check the InitializeComponent method of your application.
JoCodes 5-Nov-13 22:49pm    
IS it inside update panel ?
macmacmacmac 5-Nov-13 22:56pm    
nope.
JoCodes 5-Nov-13 22:57pm    
Ok.Make EnableViewState true both on the control and on the page and see?
JoCodes 5-Nov-13 23:59pm    
Any progress?

Tried your Code in Google chrome and IE without any change in your posted code. Both seems to be working. But in IE , the Breakpoint was not hitting for some reason . Once I tried adding the EnableViewState to true for the dropdownlist , it started to hit the break point. Can you try the same .Please revert if your still facing the issue.
 
Share this answer
 
Why no you are trying rating1.SelectedItem.Value instead of rating1.Text
 
Share this answer
 
Comments
VICK 6-Nov-13 1:06am    
To ask any question to OP, You must use "Have a Question or Comment" option.
[no name] 6-Nov-13 1:35am    
It is not a Question. Here i have given one solution. !! Look again .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900