locked
Changing label font size in dropdownlist. RRS feed

  • Question

  • User768140455 posted

    I'm having a very hard time on what I thought would be an easy assignment for a class.

    I have a label called timeLabel that simply displys the time on the webserver.  All I want, is a simple drop down list that will change the font size of the timeLabel.  In my code-behind file I have something like this:

     

    Partial Class WebTime
        Inherits System.Web.UI.Page
    
        ' initializes the contents of the page
        Protected Sub Page_Init(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Init
          
    ' display the server's current time in timeLabel timeLabel.Text = DateTime.Now.ToString("hh:mm:ss") End Sub ' Page_Init Protected Sub font_control_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles font_control.SelectedIndexChanged ' Changes the font size of timeLabel by getting a value from font_control and typecasting to int ' timeLabel.Font.Size = FontUnit.Point(Convert.ToInt32(font_control.SelectedValue)) End Sub End Class ' WebTime

    The values for each of the items in the drop down list font_control are "10", "20", and "30". I thought I could just get the value of the selected item as a string and then convert to an integer to feed into Font.Point. While everything compiles fine, whenever I test the page in a browser I get no change in the font size of my label using the drop down list.  Oh, and I do have AutoPostBack enabled on the list.

     

    I'm completley new to ASP.net and would apprieciate any help you can provide.

    Sunday, April 3, 2011 11:34 AM

Answers

  • User-691245060 posted

    use like this....

    Label1.Font.Size = FontUnit.Parse(DDL.SelectedValue.ToString())

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 3, 2011 4:15 PM

All replies

  • User-1423995609 posted

    It works fine, I mean your code, can u post markup(aspx file), or the part where u popultaing your DropDownList??? I tried your code, and it is working.

    Sunday, April 3, 2011 1:42 PM
  • User-691245060 posted

    use like this....

    Label1.Font.Size = FontUnit.Parse(DDL.SelectedValue.ToString())

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 3, 2011 4:15 PM