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

RadGrid Validate Eval inside TemplateColumn

1 Answer 306 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Diego
Top achievements
Rank 1
Diego asked on 14 May 2019, 06:51 PM

I have the followig RadGrid

<telerik:RadGrid ID="RadGrid1" OnInit="RadGrid1_Init" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        OnNeedDataSource="RadGrid1_NeedDataSource" PageSize="30"
        OnItemDataBound="RadGrid1_ItemDataBound" AllowMultiRowEdit="True"
        RenderMode="Lightweight"
        OnPreRender="RadGrid1_PreRender"
        CssClass="RadGrid_ModernBrowsers"
        OnBatchEditCommand="RadGrid1_BatchEditCommand"
        HorizontalAlign="Center" Height="740px" OnItemCreated="RadGrid1_ItemCreated" Skin="Simple" OnColumnCreating="RadGrid1_ColumnCreating" AllowFilteringByColumn="True" OnItemCommand="RadGrid1_ItemCommand" AllowSorting="True" OnBiffExporting="RadGrid1_BiffExporting">
        <GroupingSettings CollapseAllTooltip="Collapse all groups" CaseSensitive="false"></GroupingSettings>
        <MasterTableView CommandItemDisplay="Bottom" CommandItemStyle-Font-Size="10" DataKeyNames="ID_Trafo_2D" EditMode="Batch" BatchEditingSettings-EditType="Row" Font-Names="Calibri" Font-Size="8" TableLayout="Fixed">
            <ColumnGroups>
                <...>
            </ColumnGroups>
            <CommandItemSettings ShowCancelChangesButton="True"
                ShowSaveChangesButton="True"/>
            <Columns>
                <telerik:GridBoundColumn DataField="ID_Trafo_2D"
                    FilterControlAltText="Filter column column" HeaderText="Trafo 2D ID"
                    UniqueName="column" ReadOnly="True" ColumnGroupName="InformacionBasica" HeaderStyle-Font-Size="10" FilterControlWidth="70%">
                    <HeaderStyle Font-Size="10pt" Wrap="False" Width="80px" HorizontalAlign="Center"
                        BackColor="#CCCCCC"></HeaderStyle>
                    <ItemStyle Wrap="True" HorizontalAlign="Center" />
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn
                    HeaderText="Conexion1 ID" FilterControlAltText="Filter TemplateColumn1 column" UniqueName="ID_T2D_Conexion1" DataField="NombreConexion" ColumnGroupName="Caracteristicas" HeaderStyle-Font-Size="10" AutoPostBackOnFilter="false" ShowFilterIcon="true">
                    <EditItemTemplate>
                        <telerik:RadButton ID="RadButton1" runat="server" OnClientClicked="openRadWindowConexion1" Width="120%" AutoPostBack="False" Text='Editar Conexión'>
                            <Icon PrimaryIconUrl="~/Resources/EditIcon18x18.png" PrimaryIconTop="2px" PrimaryIconLeft="2px" PrimaryIconWidth="18px" PrimaryIconHeight="18px" />
                        </telerik:RadButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <%# Eval("NombreConexion")%>
                    </ItemTemplate>
                    <HeaderStyle BackColor="#DDEBF7" />
                    <ItemStyle Wrap="False" />
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn FilterControlAltText="Filter column4 column"
                    HeaderText="Nombre" FilterControlWidth="70%" UniqueName="column4" DataField="Trafo2DNombre" ColumnGroupName="DescripcionTransformadores2D" HeaderStyle-Font-Size="10" AutoPostBackOnFilter="false" ShowFilterIcon="true">
                    <ColumnValidationSettings EnableRequiredFieldValidation="True">
                        <RequiredFieldValidator ForeColor="#FF3300" ToolTip="Campo Obligatorio">(*)</RequiredFieldValidator>
                    </ColumnValidationSettings>
                    <HeaderStyle Font-Size="10pt" BackColor="#E8FFEA"></HeaderStyle>
                    <ItemStyle Wrap="False" />
                </telerik:GridBoundColumn>
            </Columns>
            <BatchEditingSettings EditType="Row"></BatchEditingSettings>
            <CommandItemStyle Font-Size="10pt"></CommandItemStyle>
        </MasterTableView>
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
            <ClientEvents OnBatchEditOpening="OnBatchEditOpening" />
        </ClientSettings>
        <PagerStyle PageSizes="15;30;90;150;300" Position="Bottom" />
        <FilterMenu RenderMode="Lightweight"></FilterMenu>
        <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
    </telerik:RadGrid>

 

When a user wants to add a new row, he has to select a name ("Nombre") and a connection ("Conexion") from a window that pops up and assigns the selected connection to the selected cell. I can validate the name using the built-in validator for BoundColumns, however, I haven't found a way to validate the Eval("NombreConexion") that is on the ItemTemplate of the GridTemplateColumn so that it is not an empty value (some users forget to assign a connection).

Is there any way of doing this? I can't use a FieldValidator because the Eval field is not a control and if I try to transform it into a radlabel I just get errors.

Thank you.

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 May 2019, 12:16 PM
Hello Diego,

In this case you have 2 options:

1. Place a RequiredFieldValidator inside the RadWindow which contains the NombreConexion textbox
2. Place a HiddenField or TextBox inside the EditItemTemplate of the ID_T2D_Conexion1 column along with a RequiredFieldValidator which will fire when the value is empty.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Diego
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or