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

Radgrid not finding range validator

2 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Dec 2011, 06:48 PM
Hello all. Been trying to solve a problem to no avail. Have tried everything I can. Basically trying to set the minimun and maximum values of a range validator residing inside RadGrid. But it's not working.

Here is my code.

    <telerik:GridTemplateColumn DataField="claim_date" DataType="System.DateTime"
        FooterText="Totals: " HeaderText="Date" SortExpression="claim_date"
        UniqueName="claim_date">
 
 
        <ItemTemplate>
            <asp:Label ID="claim_dateLabel" runat="server"
                Text='<%# Eval("claim_date", "{0:MM/dd/yyyy}") %>'></asp:Label>
                 
        </ItemTemplate>
 
         
        <EditItemTemplate>
                        <telerik:RadDatePicker ID="claim_dateTextBox" runat="server" DBSelectedDate='<%# Bind("claim_date") %>' Width="100" />
                                                           
             <asp:RequiredFieldValidator ID="fvDateRequiredFieldValidator" runat="server" ErrorMessage="Claim date is required" ControlToValidate="claim_dateTextBox" ValidationGroup="DataEntryChk" Display="Dynamic" Font-Bold="true"  />                                       
             
<asp:RangeValidator ID="fvDateValidator" Type="Date" ControlToValidate="claim_dateTextBox" runat="server" ErrorMessage="Cannot save claim item. Please select/enter a date in the same month as the voucher month." SetFocusOnError="True" ValidationGroup="DataEntryChk" Display="Dynamic" Font-Bold="true"  />  
 
        </EditItemTemplate>
 
        
    </telerik:GridTemplateColumn>


And in code behind I have the following.

Protected Sub ClaimsGV_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles ClaimsGV.ItemCommand
 
 
    If e.CommandName = RadGrid.UpdateCommandName Or e.CommandName = RadGrid.PerformInsertCommandName Or e.CommandName = RadGrid.EditCommandName Then
 
 
        Dim editform As GridEditFormItem = DirectCast(DirectCast(e.Item, Telerik.Web.UI.GridDataItem).EditFormItem, GridEditFormItem)
        'Dim editform As GridEditableItem = CType(e.Item, GridEditableItem)
 
 
        Dim fvDateValidator As RangeValidator = CType(editform.FindControl("fvDateValidator"), RangeValidator)
 
 
        If fvDateValidator IsNot Nothing And iMaxEndDate <> "" And iMinStartDate <> "" Then
            fvDateValidator.Enabled = True
            fvDateValidator.Visible = True
            fvDateValidator.MinimumValue = iMinStartDate.ToShortDateString
            fvDateValidator.MaximumValue = iMaxEndDate.Date.ToShortDateString
        End If
 
 
    End If
 
 
End Sub

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Dec 2011, 08:09 PM
Hello,

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
             
             
 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
 
                // access or set control's property here
                RadDatePicker claim_dateTextBox = item.FindControl("claim_dateTextBox") as RadDatePicker;
                RequiredFieldValidator fvDateRequiredFieldValidator = item.FindControl("fvDateRequiredFieldValidator") as RequiredFieldValidator;
            }
        }


Thanks,
Jayesh Goyani
0
John
Top achievements
Rank 1
answered on 12 Dec 2011, 08:50 PM
Thank you. That works!
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or