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

RadColorPicker in grid cell template

3 Answers 275 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 10 Sep 2008, 10:02 AM
Hi,

 I want to display a RadColorPicker in a grid cell (either in a radGrid or an Infragistics UltraWebGrid, I'm not fussy). I can't figure out how to successfully do this in an UltraWebGrid cell template, haven't tried the radGrid. Is there any sample code or advice you can send my way to achieve this?

Many Thanks,

John

3 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 12 Sep 2008, 10:16 AM
Hello John,

You can display a RadColorPicker in a grid cell by putting it into the grid column's Item Template. For RadGrid this should be done in the following manner:

   <telerik:GridTemplateColumn HeaderText="TextColor" UniqueName="TextColor">  
                            <ItemTemplate> 
                                <telerik:RadColorPicker ID="defaultRadColorPicker1" runat="server" Preset="Standard">  
                                </telerik:RadColorPicker> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 

In case your question is about binding a color, please note that you cannot provide the color through declarative binding because only primitive type properties such as string, int, bool are bindable declaratively. Therefore .

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()));  

For your convenience I attached a sample demo project which demonstrates the above mentioned approach.

All the best,
Svetlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dédé
Top achievements
Rank 1
answered on 19 May 2009, 09:52 AM
Hi,

Can you improve either RadGrid or RadColorPicker to have color-editing columns, with html color values (#FFFFFF), to have bidirectionnal databinding please ?

Thanks.

0
Georgi Tunev
Telerik team
answered on 20 May 2009, 01:23 PM
Hi Damien,

I am afraid I don't see a "color column" implemented in RadGrid in the foreseeable future, as this data type is rather rarely used in grid controls and such a task will have a very low priority in our development team. In addition, this data type does not exist in databases either.

Using a template column with a RadColorPicker as an edit control is the way to go in this scenario - template columns are by design meant for custom data types, which are presented and edited in a custom way. Here is an example of template column editing:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultCS.aspx

For convenience I attached to this thread a small sample that shows how to achieve the desired result. For demo purposes the data is stored in the session.

All the best,
Georgi Tunev
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
John
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Dédé
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or