Add ColorItems with C#

5 posts, 0 answers
  1. Martijn
    Martijn avatar
    16 posts
    Member since:
    Apr 2007

    Posted 25 Apr 2007 Link to this post

    I would like to add colors using C# instead of adding colors with APSX. I`ve found the methode for a colorRange:
    1 ColorPickerID.Items.AddRange(
        ColorPickerID.GetStandardColors()
        );  

    So addin a single color wouldn`t seem difficult:
    1 ColorPickerID.Items.Add(ColorPickerID 'coloritem'); 
    But I don`t know what to fill in for 'coloritem' to add a color, preferred a hex-value.

    Anyone knows the right syntax?
  2. Johan
    Johan avatar
    617 posts
    Member since:
    Mar 2007

    Posted 25 Apr 2007 Link to this post

    You may try something similar to:

    ColorPickerID.Items.Add(new ColorPickerItem(ColorTranslator.FromHtml("#FFFF0000")));.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Johan
    Johan avatar
    617 posts
    Member since:
    Mar 2007

    Posted 25 Apr 2007 Link to this post

    ColorTranslator is in the System.Drawing namespace btw, so you may need to add it as well, e.g. using System.Drawing
  5. Martijn
    Martijn avatar
    16 posts
    Member since:
    Apr 2007

    Posted 25 Apr 2007 Link to this post

    using System.Drawing is always included when a new ASPX file is created. But thanx for the markup.

    I`ve found the right syntax:

    1 ColorPickerID.Items.Add(  
    2     new Telerik.Web.UI.ColorPickerItem(  
    3        ColorTranslator.FromHtml("#FFFF0000")  
    4     )  
    5 ); 
  6. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 25 Apr 2007 Link to this post

    Martijntijn-

    You may also consider adding a "using Telerik.Web.UI" to your code if you're going to be doing a lot server side to make your code easier to read and to save you from typing the fully qualified type each time you add a color.

    Thanks~
    Todd
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017