Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Grid / Flexible Server-Side Validation

Next database reset in 0 hours, 53 minutes, 18 seconds
Example Configuration
Edit options

Validation options Choose validation group

Add new recordRefresh
 IDProductNameSupplierCategoryUnits In StockDiscontinuedUnitPrice 
Add new recordRefresh
Page size:
select
 65 items in 22 pages
5Chef Anton's GumboNew Orleans Cajun DelightsCondiments0 $21.35
6Grandma's Boysenberry SpreadGrandma Kelly's HomesteadCondiments120 $25.00
7Uncle Bob's Organic Dried PearsGrandma Kelly's HomesteadProduce15 $30.00
Edit properties of Product Uncle Bob's Organic Dried Pears
select
select

*


Enter value which doesn't start with '4'
 
 
FormValidationGroup
City:
State:
SearchValidationGroup
Enter criteria:



  • To test the functionality on this example :
    • Switch the edit modes using the Edit options menu at the top
    • Enable/disable the validation for the grid using the checkbox from the Validation options menu
    • Choose a validation group for the grid edit form controls by selecting an option from the dropdown list from the Validation options menu

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="Grid.Examples.DataEditing.Validation.DefaultVB" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag>
        <!-- custom head section -->
        <style type="text/css">
            .MyImageButton
            {
                cursor: hand;
            }
            div.qsf_wrapper
            {
                width: 1250px;
            }
            div.qsf_footer
            {
                float: left;
                width: 700px;
            }
        </style>
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form id="mainForm" runat="server">
        <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB" ShowDbResetTimer="true"></telerik:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <!-- content start -->
        <telerik:ConfiguratorPanel ID="ConfiguratorPanel1" runat="server" Expanded="true">
            <div class="module" style="width: 78%;">
                <div style="float: left; margin-top: 5px;">
                    <b>Edit options</b>
                </div>
                <div style="float: left; margin-left: 10px;">
    <asp:RadioButton ID="RadioButton1" AutoPostBack="True" Text="In-forms editing mode"
    runat="server" Checked="True"></asp:RadioButton>

                </div>
                <div style="float: left;">
    <asp:RadioButton ID="RadioButton2" AutoPostBack="True" Text="In-line editing mode"
    runat="server"></asp:RadioButton>

                </div>
                <div style="float: left; margin-left: 20px;">
                    <asp:CheckBox ID="CheckBox1" Text="Allow multi-row edit" AutoPostBack="True" runat="server" />
                </div>
                <div style="clear: both;">
                </div>
                <hr />
                <div>
                    <b>Validation options</b>
    <asp:CheckBox ID="RadioButton3" AutoPostBack="True" Text="Enable/disable validation"
    runat="server" Checked="True"></asp:CheckBox>

                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                        <asp:ListItem Text="No group chosen" Value="NoGroup" Selected="true" />
                        <asp:ListItem Text="FormValidationGroup" Value="FormGroup" />
                        <asp:ListItem Text="SearchValidationGroup" Value="SearchGroup" />
                    </asp:DropDownList>
    <asp:Label ID="lblMessage" runat="server" EnableViewState="false" BackColor="Beige"
    Text="Choose validation group" />

                </div>
            </div>
        </telerik:ConfiguratorPanel>
        <br />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator3" />
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator4" />
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator5" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadioButton1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        <telerik:AjaxUpdatedControl ControlID="RadioButton2" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadioButton2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        <telerik:AjaxUpdatedControl ControlID="RadioButton1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="CheckBox1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="CheckBox2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="DropDownList1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
            PageSize="3" AllowSorting="true" AllowAutomaticUpdates="True" AllowPaging="True"
            AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnItemUpdated="RadGrid1_ItemUpdated"
            OnDataBound="RadGrid1_DataBound" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
            ShowStatusBar="true" OnPreRender="RadGrid1_PreRender">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="ProductID"
                DataSourceID="SqlDataSource1" HorizontalAlign="NotSet" AutoGenerateColumns="False">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        <HeaderStyle Width="20px" />
                        <ItemStyle CssClass="MyImageButton" />
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="ProductID" HeaderText="ID" ReadOnly="True" SortExpression="ProductID"
                        UniqueName="ProductID">
                        <HeaderStyle Width="20px" ForeColor="Silver" />
                        <ItemStyle ForeColor="Silver" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
                        UniqueName="ProductName">
                    </telerik:GridBoundColumn>
                    <telerik:GridDropDownColumn DataField="SupplierID" DataSourceID="SqlDataSource2"
                        HeaderText="Supplier" ListTextField="CompanyName" ListValueField="SupplierID"
                        UniqueName="SupplierID">
                    </telerik:GridDropDownColumn>
                    <telerik:GridDropDownColumn DataField="CategoryID" DataSourceID="SqlDataSource3"
                        HeaderText="Category" ListTextField="CategoryName" ListValueField="CategoryID"
                        UniqueName="CAtegoryID">
                    </telerik:GridDropDownColumn>
                    <telerik:GridBoundColumn DataField="UnitsInStock" HeaderText="Units In Stock" SortExpression="UnitsInStock"
                        UniqueName="UnitsInStock">
                        <HeaderStyle Width="50px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit"
                        SortExpression="QuantityPerUnit" UniqueName="QuantityPerUnit" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridCheckBoxColumn DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued"
                        UniqueName="Discontinued" EditFormColumnIndex="1">
                        <HeaderStyle Width="50px" />
                    </telerik:GridCheckBoxColumn>
                    <telerik:GridBoundColumn DataField="UnitsOnOrder" HeaderText="Units On Order" SortExpression="UnitsOnOrder"
                        UniqueName="UnitsOnOrder" Visible="false" EditFormColumnIndex="1">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="UnitPrice" SortExpression="UnitPrice" UniqueName="TemplateColumn"
                        EditFormColumnIndex="1">
                        <HeaderStyle Width="80px" />
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblUnitPrice" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <br />
                            <asp:TextBox runat="server" ID="tbUnitPrice" Width="50px" Text='<%# Bind("UnitPrice") %>'></asp:TextBox>
                            <span style="color: Red">*</span><br /><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbUnitPrice"
    ErrorMessage="This field is required" Display="Dynamic" runat="server">

                            </asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn Visible="false" UniqueName="UnitPrice1" ReadOnly="true"
                        ForceExtractValue="InBrowseMode" DataField="UnitPrice">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Reorder level" SortExpression="ReorderLevel"
                        UniqueName="ReorderLevelColumn" EditFormColumnIndex="1" Visible="false">
                        <HeaderStyle Width="80px" />
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblReorderLevel" Text='<%# Eval("ReorderLevel", "{0:C}") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <br />
                            <asp:TextBox runat="server" ID="tbReorderLevel" Text='<%# Bind("ReorderLevel") %>'></asp:TextBox>
                            <div style="color: Maroon;">
                                Enter value which doesn't start with '4'</div>
    <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Invalid input"
    ControlToValidate="tbReorderLevel" OnServerValidate="CustomValidator1_ServerValidate">

                            </asp:CustomValidator>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton"
                        CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                        <HeaderStyle Width="20px" />
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings ColumnNumber="2" CaptionDataField="ProductName" CaptionFormatString="Edit properties of Product {0}">
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                    <FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" BackColor="White"
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px"
                        BackColor="White" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>
        <div style="width: 78%">
            <table width="100%">
                <tr>
                    <td style="width: 60%">
                        <fieldset>
                            <legend>FormValidationGroup</legend>
                            <dl>
                                <dt>City: </dt>
                                <dd>
                                    <asp:TextBox runat="server" ID="city"></asp:TextBox>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator4" ControlToValidate="city"
    Display="Dynamic" ErrorMessage="City is required" ValidationGroup="FormValidationGroup" />

                                </dd>
                                <dt>State: </dt>
                                <dd>
                                    <asp:TextBox runat="server" ID="state"></asp:TextBox>
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="state"
    Display="Dynamic" ErrorMessage="State is required" ValidationGroup="FormValidationGroup" />

                                </dd>
                                <dd style="margin-top: 11px;">
    <asp:Button CausesValidation="true" runat="server" ID="Button1" CssClass="button"
    Text="PostBack" ValidationGroup="FormValidationGroup" />

                                </dd>
                            </dl>
                        </fieldset>
                    </td>
                    <td style="width: 40%" valign="top">
                        <fieldset>
                            <legend>SearchValidationGroup</legend>
                            <dl>
                                <dt>Enter criteria: </dt>
                                <dd>
                                    <asp:TextBox runat="server" ID="name"></asp:TextBox>
    <asp:Button ID="btnSearch" runat="server" Text="PostBack" ValidationGroup="SearchValidationGroup"
    CssClass="button" />

    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3" ControlToValidate="name"
    Display="Dynamic" ErrorMessage="Criteria is required" ValidationGroup="SearchValidationGroup" />

                                </dd>
                            </dl>
                        </fieldset>
                    </td>
                </tr>
            </table>
        </div>
        <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"

            DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID"
            InsertCommand="INSERT INTO [Products] ([ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued]) VALUES (@ProductName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)"
            SelectCommand="SELECT * FROM [Products]"
            UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [SupplierID] = @SupplierID, [CategoryID] = @CategoryID, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [UnitsOnOrder] = @UnitsOnOrder, [ReorderLevel] = @ReorderLevel, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
            <DeleteParameters>
                <asp:Parameter Name="ProductID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="SupplierID" Type="Int32" />
                <asp:Parameter Name="CategoryID" Type="Int32" />
                <asp:Parameter Name="QuantityPerUnit" Type="String" />
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="UnitsInStock" Type="Int16" />
                <asp:Parameter Name="UnitsOnOrder" Type="Int16" />
                <asp:Parameter Name="ReorderLevel" Type="Int16" />
                <asp:Parameter Name="Discontinued" Type="Boolean" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="ProductName" Type="String" />
                <asp:Parameter Name="SupplierID" Type="Int32" />
                <asp:Parameter Name="CategoryID" Type="Int32" />
                <asp:Parameter Name="QuantityPerUnit" Type="String" />
                <asp:Parameter Name="UnitPrice" Type="Decimal" />
                <asp:Parameter Name="UnitsInStock" Type="Int16" />
                <asp:Parameter Name="UnitsOnOrder" Type="Int16" />
                <asp:Parameter Name="ReorderLevel" Type="Int16" />
                <asp:Parameter Name="Discontinued" Type="Boolean" />
                <asp:Parameter Name="ProductID" Type="Int32" />
            </UpdateParameters>
        
        </asp:SqlDataSource>
        <br />
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [SupplierID], [CompanyName] FROM [Suppliers]">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
        </asp:SqlDataSource>
        <!-- content end -->
        <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451