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

How to binding a radcolorpicker in batch edit mode

1 Answer 29 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Melvin asked on 20 Jul 2015, 03:51 PM


 I have a trouble when i try binding a radcolorpicker, because this control does not show the color saved in the database.

What is wrong?

 Code .Aspx

<telerik:RadGrid id="rgCategoria"
    <MasterTableView DataKeyNames="IdCategoria"
        AutoGenerateColumns="False" commanditemdisplay="Top">
            <telerik:GridBoundColumn DataField="Nombre" UniqueName="Nombre" HeaderText="Nombre">
                <HeaderStyle Width="100px"></HeaderStyle>
            <telerik:GridTemplateColumn DataField="Color"
                    <div style='width: 150px; height: 16px; background-color: <%# Eval("Color") %>'></div>
                    <telerik:RadColorPicker runat="server" ID="txtColor"
                        <Localization ApplyButtonText="Aplicar" 
                            NoColorText="Ningún Color"
                            PickColorText="Elegir Color"
                            WebPaletteTabText="Paleta Web"
                            BlankColorText="Color Blanco"
                            CustomColor="Color Personalizado"
                            HexInputTitle="Código del color hexadecimal "
                            RecentColors="Colores Recientes"
                            CurrentColorText="(Color Actual es {0})"/>
                <HeaderStyle Width="150px">
             <telerik:GridBoundColumn DataField="IdCategoria" Display="false"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="RowVersion" Display="false"></telerik:GridBoundColumn>
        <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click"  />

Code c#

protected void rgCategoria_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    if (ViewState["dtCategoriasColores"] != null)
        rgCategoria.DataSource = (DataTable)ViewState["dtCategoriasColores"];
protected void rgCategoria_ItemDataBound(object sender, GridItemEventArgs e)
    if (e.Item is GridDataItem && e.Item.IsInEditMode)
        GridDataItem editItem = (GridDataItem)e.Item;
        RadColorPicker colorLetraRadColorPicker = (RadColorPicker)editItem.FindControl("txtColor");
        colorLetraRadColorPicker.SelectedColor = System.Drawing.ColorTranslator.FromHtml((DataBinder.Eval(e.Item.DataItem, "Color").ToString()));
protected void rgCategoria_ItemCommand(object sender, GridCommandEventArgs e)
    if (e.CommandName == RadGrid.UpdateCommandName)
        GridEditableItem editedItem = e.Item as GridEditableItem;
        RadColorPicker colorRCP = (RadColorPicker)editedItem.FindControl("txtColor");
        if (colorRCP != null)
            colorRCP.SelectedColor = System.Drawing.ColorTranslator.FromHtml((DataBinder.Eval(e.Item.DataItem, "Color").ToString()));
protected void rgCategoria_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    foreach (GridBatchEditingCommand command in e.Commands)
        if ((command.Type == GridBatchEditingCommandType.Update))
            Hashtable newValues = command.NewValues;
            Hashtable oldValues = command.OldValues;
            string OrderID = newValues["Nombre"].ToString();
            string ShipName = newValues["Color"].ToString();

1 Answer, 1 is accepted

Sort by
Konstantin Dikov
Telerik team
answered on 23 Jul 2015, 08:45 AM
Hi Melvin,

RadGrid with Batch Editing does not support the scenario that you have out-of-the-box and you will have to manually handle the grid events for getting and settings values from and to the cell and the editor. Detailed information and examples on this matter could be found in the following forum thread:
As for the OnItemDataBound approach that you are trying to use, please note that with Batch Editing, the grid will generate only one editor for the entire column and it is not possible to set values for the editor per row on server-side. Such requirements must be handled on client-side when using Batch edit mode.

Konstantin Dikov
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question