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

Rad Grid TemplateColums Compare Validator

2 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
waruni
Top achievements
Rank 1
waruni asked on 23 Feb 2010, 05:55 AM

Hi,

In Rad grid Control, there are 2 TemplateColums (Start time and end time) and it has two RadTimePicker control for      EditItemTemplate .im using the master page as well.
I want to validate that end time value is greater than the start time .
 How to use Compare Validator?

Can you plz tell me the way of doing this.because this is ugent.

<telerik:GridTemplateColumn HeaderText="Starttime" UniqueName="Starttime" >    
            <EditItemTemplate>    
                <telerik:RadTimePicker ID="rtpStartTime" runat="server">     
                </telerik:RadTimePicker>    
             </EditItemTemplate>    
            <ItemTemplate>    
                <asp:Label ID="lblStarttime" runat="server" Text='<%# Eval("StartTime","{0:t}") %>'></asp:Label>    
            </ItemTemplate>    
        </telerik:GridTemplateColumn>    
             
         <telerik:GridTemplateColumn HeaderText="End time" UniqueName="EndTime">     
            <EditItemTemplate>    
                <telerik:RadTimePicker ID="rtpEndTime" runat="server"       
                </telerik:RadTimePicker>                     
            </EditItemTemplate>    
            <ItemTemplate>    
                <asp:Label ID="lblEndTime" runat="server" Text='<%# Eval("EndTime", "{0:t}") %>'></asp:Label>    
            </ItemTemplate>    
 

Thanks
Waruni

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Feb 2010, 06:56 AM
Hi Waruni,

You can add CompareValidator from code behind as shown below.

CS:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
            RadTimePicker start = (RadTimePicker)item.FindControl("rtpStartTime"); 
            RadTimePicker end = (RadTimePicker)item.FindControl("rtpEndTime"); 
 
            TableCell cell = (TableCell)start.Parent; 
 
            CompareValidator val = new CompareValidator(); 
            val.ControlToCompare = start.ID; 
            val.ControlToValidate = end.ID; 
            val.Operator = ValidationCompareOperator.GreaterThan; 
            val.ErrorMessage = "Error message"
            cell.Controls.Add(val); 
        }  
    } 

All the best,
Shinu.
0
waruni
Top achievements
Rank 1
answered on 23 Feb 2010, 11:08 AM
hi,
Thanks for ur quick reposnse. its working fine, :)

Im use the validation summary for displaying the  Error Messages  . but when i clicked on cancel button in GridEdit Command Column validation summary box doenst clear the validations.

Can you plz tell me the way of doing this.because this is ugent.
 
waruni
Tags
Grid
Asked by
waruni
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
waruni
Top achievements
Rank 1
Share this question
or