This is a migrated thread and some comments may be shown as answers.

cannot get HEX color value in .cs page:

2 Answers 142 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
nagarjun
Top achievements
Rank 1
nagarjun asked on 09 Mar 2009, 02:39 PM
Hi,

    In my project i need to use Color picker in Grid and get this HEX color value which is choosen and save to database for further usage.

    In Grid i have used Template column for color picker as follows:

<telerik:GridTemplateColumn HeaderText="Color" UniqueName="Color" Visible="false">
        <ItemTemplate>
        </ItemTemplate>
        
<EditItemTemplate>        
<telerik:RadColorPicker runat="server" ID="RadColorPicker1" OnClientColorChange="HandleColorChange" Preset="Standard" Width="170"/>
<input type="text" value="" id="HEXColor" />
        </EditItemTemplate>
        </telerik:GridTemplateColumn>


When clicked on color on color picker items, the HEX color value is displayed in input type 'HEXColor' as text by using javascript functions as follows:

function HandleColorChange(sender,eventArgs)
                    {
                    $get("HEXColor").value=sender.get_selectedColor();
                    } 

Here the problem is: because i need to save this HEX value into database i need this HEX value which is displayed in input type text field(id=HEXColor) to be accessed in .cs page.
Please, let me know how to access this HEX value in .cs page. And its not compulsory that i have to use input type i can also use lable, textbox.


Thanks,
Nagarjun S.

2 Answers, 1 is accepted

Sort by
0
nagarjun
Top achievements
Rank 1
answered on 10 Mar 2009, 11:17 AM
Hi,

   I have changed the above functionality a little bit and able to get colorPicked value in .cs page.

   The other thing now is .. i have converted the color clicked by user to RGB value say 125,25,100 ans saved it to database. Now i need to any of the thing below.

1) make the ColorPicker selected color to that color which is previously saved in database(125,25,100) i.e)colorPicker shd be in selected mode to color 125,25,100.

2)or use template column in grid and display that saved color in database. So that user can see that template and knows which color was previously there.

Thanks,
Nagarjun S. 
0
Svetlina Anati
Telerik team
answered on 11 Mar 2009, 02:30 PM

Hi nagarjun,

I assume that you have tried yourself to bind declaratively color pickers in a grid template in the standard manner you declaratively databing controls. The problem in this setup is caused by the fact that only primitive type properties such as string, int, bool are bindable declaratively. Therefore you cannot provide the color through declarative binding.

What I can suggest is to use the RadGrid's Item_DataBound server event handler and set the selected color  using the code behind where you can do the needed casts as shown below:

 picker.SelectedColor = ColorTranslator.FromHtml((DataBinder.Eval(e.Item.DataItem, "Color").ToString()));   

Best wishes,

Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ColorPicker
Asked by
nagarjun
Top achievements
Rank 1
Answers by
nagarjun
Top achievements
Rank 1
Svetlina Anati
Telerik team
Share this question
or