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

How to validate a date filter

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dexter McCloud
Top achievements
Rank 1
Dexter McCloud asked on 25 Mar 2010, 04:07 PM

I have a grid that displays a DateTime field.  The user has the ability to filter this DateTime field. I want to make sure the user enters only valid DateTime values (i.e. 1/1/2010).  So, how can I check the filter?  I wrote the following code in the grid ItemCommand event but I don't know how to complete it.  Can someone tell me which property to check so I can make sure that what the user entered is a valid date?

protected void gridMain_ItemCommand(object sender, GridCommandEventArgs e)  
{  
 
  if (e.Item is GridFilteringItem)  
  {  
      GridFilteringItem FilteringItem = e.Item as GridFilteringItem;  
 
      // what do I do now?    
   }  
 
}  
 
 

1 Answer, 1 is accepted

Sort by
0
Foenix
Top achievements
Rank 1
answered on 25 Mar 2010, 04:40 PM
Yes, I can.

protected void gridMain_ItemCommand(object sender, GridCommandEventArgs e) 
    // Not sure about e.Item is GridFilteringItem, I use usually e.CommandName == "Filter" 
    if (e.Item is GridFilteringItem)   
    {   
        GridFilteringItem FilteringItem = e.Item as GridFilteringItem;   
  
        // what do I do now?     
        Pair args = (Pair)e.CommandArgument; 
         
        string columnName = args.Second.ToString(); 
        GridColumn col = gridMain.MasterTableView.GetColumnSafe(columnName); 
         
        //col.CurrentFilterValue contains user input, so you can validate it 
        // Just in case: args.First contains FilteringFunction to be applied 
   }   

Tags
Grid
Asked by
Dexter McCloud
Top achievements
Rank 1
Answers by
Foenix
Top achievements
Rank 1
Share this question
or