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

Validation in grid

3 Answers 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
xvikx
Top achievements
Rank 1
xvikx asked on 28 Feb 2012, 01:48 PM
Hi.
I have a RadDateTimePicker in a grid.How i can compare SelectedDate(DateTime type!)  with today's date?
My code:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            RadDateTimePicker startDate = (RadDateTimePicker)item.FindControl("startDate");
 
            TableCell cell = (TableCell)start.Parent;
 
            CompareValidator CV1 = new CompareValidator();
            CV1.ErrorMessage = "*";
            CV1.ControlToValidate = startDate.ID;
            CV1.Operator = ValidationCompareOperator.GreaterThanEqual;
            CV1.ValueToCompare = DateTime.Now.ToString();
            cell.Controls.Add(CV1);
 
            }
      }
Please help,
Thanks.

3 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 28 Feb 2012, 02:10 PM
Hello,

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridDataInsertItem)
        {
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
            RadDateTimePickerdatepick1 = (RadDateTimePicker)insertItem["HoldiayStartDate"].Controls[1]; // HoldiayStartDate is Column Unique Name
            datepick1.MinDate = DateTime.Now;
        }
        if (e.Item.IsInEditMode)
        {
            GridEditableItem insertItem = (GridEditableItem)e.Item;
            RadDateTimePickerdatepick1 = (RadDateTimePicker)insertItem["HoldiayStartDate"].Controls[1]; // HoldiayStartDate is Column Unique Name
            datepick1.MinDate = DateTime.Now;
        }
    }


Thanks,
Jayesh Goyani
0
Jayesh Goyani
Top achievements
Rank 2
answered on 28 Feb 2012, 02:13 PM
Hello,

protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e) 
    
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        
            GridDateTimeColumnEditor columnEditor = 
                ((GridEditableItem) e.Item).EditManager.GetColumnEditor("Date1") as GridDateTimeColumnEditor; 
  
            TableCell cell = (TableCell) columnEditor.PickerControl.Parent; 
  
            CompareValidator compareValidator = new CompareValidator(); 
            compareValidator.ID = "compareValidator"
            compareValidator.ControlToValidate = columnEditor.PickerControl.ID; 
            compareValidator.Operator = ValidationCompareOperator.GreaterThanEqual; 
            compareValidator.Type = ValidationDataType.Date; 
            compareValidator.ErrorMessage = "*"
            compareValidator.ValueToCompare = DateTime.Now.ToShortDateString(); 
            cell.Controls.Add(compareValidator); 
        
    }




Thanks,
Jayesh Goyani
0
xvikx
Top achievements
Rank 1
answered on 29 Feb 2012, 07:03 AM
Thank you. It worked 
Tags
Grid
Asked by
xvikx
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
xvikx
Top achievements
Rank 1
Share this question
or