I have a Radgrid with batch edit mode. I a drop down list "On_maintenance" and a datepicker "Maintenance_EXP_DT", I wanted to add validation to the datepicker only if the drop down list value is "Yes".
Example:
If drop down list value is "yes" then datepicker is mandatory, else datepicker is optional.
Below is my code:
<telerik:GridTemplateColumn FilterDelay="1000" ShowFilterIcon="true" DataField="On_Maintenance" HeaderText="On Maintenance" UniqueName="On_Maintenance" ItemStyle-Width="100px" HeaderStyle-Width="100px" SortExpression="On_Maintenance">
<FilterTemplate>
<telerik:RadComboBox ID="cmbOn_Maintenance" DataTextField="On_Maintenance" Width="80px"
DataValueField="On_Maintenance" maxHeight="200px" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("On_Maintenance").CurrentFilterValue %>'
runat="server" OnClientSelectedIndexChanged="On_MaintenanceChanged">
<Items>
<telerik:RadComboBoxItem Text="" />
<telerik:RadComboBoxItem Text="No" Value="No" />
<telerik:RadComboBoxItem Text="Yes" Value="Yes" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="sbOn_Maintenance" runat="server">
<script type="text/javascript">
function On_MaintenanceChanged(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
tableView.filter("On_Maintenance", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<%# Eval("On_Maintenance") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList runat="server" ID="ddlOn_Maintenance" DataTextField="On_Maintenance" DataValueField="On_Maintenance" Width="80px">
<Items>
<telerik:DropDownListItem Text="No" Value="0"/>
<telerik:DropDownListItem Text="Yes" Value="1"/>
</Items>
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn FilterDelay="1000" ShowFilterIcon="true" HeaderText="Maintenance Exp Date" DataField="Maintenance_Exp_DT" UniqueName="Maintenance_Exp_DT" ItemStyle-Width="200px" HeaderStyle-Width="200px" SortExpression="Maintenance_Exp_DT">
<FilterTemplate>
<telerik:RadDatePicker id="dpMaintenance_Exp_DT" runat="server"
ClientEvents-OnDateSelected="Maintenance_Exp_DTChanged">
<DateInput runat="server" DateFormat="yyyy-MM-dd"></DateInput>
</telerik:RadDatePicker>
<telerik:RadScriptBlock ID="sbMaintenance_Exp_DT" runat="server">
<script type="text/javascript">
function Maintenance_Exp_DTChanged(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var DatePicker = $find('<%# ((GridItem)Container).FindControl("dpMaintenance_Exp_DT").ClientID %>');
//var date = FormatSelectedDate(sender.toString());
var Date = FormatSelectedDate(DatePicker);
//alert(Date);
tableView.filter("Maintenance_Exp_DT", Date , "EqualTo");
}
function FormatSelectedDate(picker) {
var date = picker.get_selectedDate();
var dateInput = picker.get_dateInput();
var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
return formattedDate;
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<%# Eval("Maintenance_Exp_DT") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker id="dpMaintenance_Exp_DT1" runat="server" >
<DateInput runat="server" DateFormat="yyyy-MM-dd"></DateInput>
</telerik:RadDatePicker>
<%--<asp:RequiredFieldValidator ID="rfvMaintenance_Exp_DT1" ForeColor="Red" runat="server" ErrorMessage="This field is mandatory" ControlToValidate="dpMaintenance_Exp_DT1"></asp:RequiredFieldValidator>--%>
</EditItemTemplate>
</telerik:GridTemplateColumn>