RadGrid Validate Eval inside TemplateColumn

2 posts, 0 answers
  1. Diego
    Diego avatar
    9 posts
    Member since:
    Jun 2018

    Posted 14 May Link to this post

    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.

     

  2. Eyup
    Admin
    Eyup avatar
    3817 posts

    Posted 17 May Link to this post

    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.
Back to Top