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
Grid
This is a migrated thread and some comments may be shown as answers.
Melvin
Top achievements
Rank 1
Melvin asked on 20 Jul 2015, 03:51 PM

Hi,

 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"
    runat="server"
    AutoGenerateColumns="False"
    AllowAutomaticUpdates="True"
    AllowAutomaticInserts="True"
    OnNeedDatasource="rgCategoria_NeedDataSource"
    Culture="es-ES"
    GroupPanelPosition="Top"
    OnBatchEditCommand="rgCategoria_BatchEditCommand"
    OnItemCommand="rgCategoria_ItemCommand"
    OnItemDataBound="rgCategoria_ItemDataBound">
    <MasterTableView DataKeyNames="IdCategoria"
        EditMode="Batch"
        AutoGenerateColumns="False" commanditemdisplay="Top">
        <commanditemsettings
            addnewrecordtext="Nuevo"
            cancelchangestext="Cancelar"
            refreshtext="Refrescar"
            savechangestext="Guardar"
            showcancelchangesbutton="True"
            showsavechangesbutton="True">
        </commanditemsettings>
        <Columns>
            <telerik:GridBoundColumn DataField="Nombre" UniqueName="Nombre" HeaderText="Nombre">
                <HeaderStyle Width="100px"></HeaderStyle>
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn DataField="Color"
                UniqueName="Color"
                HeaderText="Color">
                <ItemTemplate>
                    <div style='width: 150px; height: 16px; background-color: <%# Eval("Color") %>'></div>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadColorPicker runat="server" ID="txtColor"
                        PaletteModes="HSB" 
                        ShowIcon="True">
                        <Localization ApplyButtonText="Aplicar" 
                            NoColorText="Ningún Color"
                            PickColorText="Elegir Color"
                            WebPaletteTabText="Paleta Web"
                            BlankColorText="Color Blanco"
                            CancelButtonText="Cancelar"
                            CustomColor="Color Personalizado"
                            HexInputTitle="Código del color hexadecimal "
                            HSBSliderDragText="Arrastrar"
                            HSVSliderDragText="Arrastrar"
                            OkButtonText="Aceptar"
                            RecentColors="Colores Recientes"
                            RGBSlidersDecreaseText="Disminuir"
                            RGBSlidersDragText="Arrastrar"
                            RGBSlidersIncreaseText="Aumentar"
                            CurrentColorText="(Color Actual es {0})"/>
                    </telerik:RadColorPicker>
                </EditItemTemplate>
 
                <HeaderStyle Width="150px">
                </HeaderStyle>
            </telerik:GridTemplateColumn>
             <telerik:GridBoundColumn DataField="IdCategoria" Display="false"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="RowVersion" Display="false"></telerik:GridBoundColumn>
        </Columns>
        <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click"  />
    </MasterTableView>
     
</telerik:RadGrid>

Code c#

protected void rgCategoria_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    if (ViewState["dtCategoriasColores"] != null)
    {
        rgCategoria.DataSource = (DataTable)ViewState["dtCategoriasColores"];
    }
    else
    {
        CargarCategoriaColores();
    }
}
 
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
0
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.


Regards,
Konstantin Dikov
Telerik
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
Tags
Grid
Asked by
Melvin
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or