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

How to access all fields in row for custom validator

1 Answer 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon Ingersoll
Top achievements
Rank 1
Jon Ingersoll asked on 16 Apr 2010, 04:26 PM
Hola,

I'm currently developing a form using a radgrid to allow users to register multiple guests for an event. Each row in the grid is a guest and the grid is editable to allow the users to add their own guests.

Two of the columns are Age & GuestOption
<telerik:GridTemplateColumn UniqueName="Age" HeaderText="Age (Child Only)"
                <ItemTemplate> 
                    <asp:Label runat="server" ID="lblAge" Text='<%# Bind("Age") %>'></asp:Label> 
                </ItemTemplate> 
                <EditItemTemplate> 
                    <asp:TextBox runat="server" ID="editAge" Text='<%# Bind("Age") %>' Width="20px"></asp:TextBox> 
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="editAge" runat="server" ValidationExpression="^[0-1]?[0-7]$" ErrorMessage="Whole numbers, under 18"></asp:RegularExpressionValidator> 
                </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridDropDownColumn DataField="GuestOptionsID" DataSourceID="GuestOptionsDataSource" 
                HeaderText="Options" ListTextField="GuestOption" ListValueField="GuestOptionsID" 
                UniqueName="GuestOption" ColumnEditorID="GuestOptionsIDEditor"
            </telerik:GridDropDownColumn> 

<asp:SqlDataSource ID="GuestOptionsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:edu_yale_som_alumnireunion_connectionstring %>" 
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT [GuestOptionsID], [GuestOption] FROM [GuestOptions] WHERE Visible='true' order by DisplayOrder"
</asp:SqlDataSource> 


I have age being validated so that if they enter an age is needs to be less than 18. But, I also need to validate based on the option the select in the GuestOption drop down.

I'm trying to use a custom validator, but I need to be able to have access to both the value in the Age column & the value in the GuestOption drop down. Is there an easy way for me to access both those values during the validation? I can just do this all after the post the form, but I would prefer to do this with validation so that they cannot enter invalid data from the get go.

thanks,

-Jon

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 19 Apr 2010, 09:31 AM
Hi Jon,

How to access grid cells and controls inside them you can see from the following online resources:

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

Additionally, you may consider using RadInputManager with numeric input setting (instead of RegularExpressionValidator) in order to restrict the user entries for age to numeric values only and specify acceptable range for the entered values. See the implementation from this online demo for more info.

Best regards,
Sebastian
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Jon Ingersoll
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or