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

Validation for RadDropDownList in Grid EditItemTemplate

3 Answers 503 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DRG
Top achievements
Rank 1
DRG asked on 14 Feb 2014, 10:41 PM

Validation works fine for RadTextBox but doesn't work for RadDropDownList. Need Initial value to be select.

01.<telerik:GridTemplateColumn HeaderText="SOURCE" HeaderStyle-Width="85px" UniqueName="SourceKey"
02.                                           DataField="SourceKey" Visible="true" SortExpression="Source">
03.                                           <ItemTemplate>
04.                                               <%# Eval("Source")%>
05.                                           </ItemTemplate>
06.                                           <EditItemTemplate>
07.                                               <span>
08.                                                   <telerik:RadDropDownList runat="server" ID="rddlSources" DataSourceID="odsSources"
09.                                                       DataValueField="SourceKey" DataTextField="Source" Width="83px" DefaultMessage="Select">
10.                                                   </telerik:RadDropDownList>
11.                                                   <span style="color: Red">
12.                                                       <asp:RequiredFieldValidator ID="rfvSource" ControlToValidate="rddlSources" ErrorMessage="*Required"
13.                                                           runat="server" Display="Dynamic">
14.                                                       </asp:RequiredFieldValidator>
15.                                                   </span></span>
16.                                           </EditItemTemplate>
17.                                       </telerik:GridTemplateColumn>
18.                                       <telerik:GridTemplateColumn HeaderText="ACCOUNT" HeaderStyle-Width="100px" SortExpression="Account"
19.                                           UniqueName="Account" DataField="Account">
20.                                           <ItemTemplate>
21.                                               <asp:Label runat="server" ID="lblAccount" Text='<%# Eval("Account") %>'></asp:Label>
22.                                           </ItemTemplate>
23.                                           <EditItemTemplate>
24.                                               <span>
25.                                                   <telerik:RadTextBox Width="98px" runat="server" ID="rtxtAccount">
26.                                                   </telerik:RadTextBox>
27.                                                   <span style="color: Red">
28.                                                       <asp:RequiredFieldValidator ID="rfvAccount" ControlToValidate="rtxtAccount" ErrorMessage="*Required"
29.                                                           runat="server" Display="Dynamic">
30.                                                       </asp:RequiredFieldValidator>
31.                                                   </span></span>
32.                                           </EditItemTemplate>
33.                                       </telerik:GridTemplateColumn>

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Feb 2014, 04:31 AM
Hi,

I have tried your code and it works fine at my end. The RequiredFieldValidator fires when no item is selected in the DropDownList. You can set InitialValue for the validator to select as follows:

ASPX:
<EditItemTemplate>
    <telerik:RadDropDownList runat="server" ID="RadDropDownList" DataSourceID="SqlDataSource" DataValueField="ID" DataTextField="City" DefaultMessage="Select">
    </telerik:RadDropDownList>
    <asp:RequiredFieldValidator ID="Validator" ControlToValidate="RadDropDownList" ErrorMessage="*Required" runat="server" Display="Dynamic" InitialValue="Select" ForeColor="Red">
    </asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Shinu
0
DRG
Top achievements
Rank 1
answered on 15 Feb 2014, 06:57 PM
This is on a RadGrid with Batch edit mode. Attached Image showing validator not being fired.  Works fine if pulled out of the grid.

Thanks.
0
Angel Petrov
Telerik team
answered on 19 Feb 2014, 02:04 PM
Hi,

Please try replacing the RadDropDownList with a RadComboBox and test whether this resolves the problem. Additionally you can try validating the cell manually by cancelling the OnBatchEditClosing event if a value is not selected in the drop down.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
DRG
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DRG
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or