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

[Solved] Don't want textboxes leave a blank value or some negative value during insert/update mode

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 15 Jun 2009, 02:16 PM
Hi,

When i press "Refresh" button on the grid, the grid is not refreshing.  

Whenever a textboxes leave a blank value or some negative value during insert/update mode, i want to display a message to the user that this is not allowed. The records will not be inserted/updated when leaves blank  or entered negative values.

Thanks.

Regards
Arshad

2 Answers, 1 is accepted

Sort by
0
Accepted
Curtis
Top achievements
Rank 1
answered on 15 Jun 2009, 03:46 PM
If you want to use custom validation you can always use the UpdateCommand and InsertCommand events of the grid.  If the validation fails set e.cancel = true and the editform will retain what the user has already entered.  If the validation succeeds then insert/update the record to the database.

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)  
    {  
      ResetErrorSummary();  
 
      bool bHasErrors = false;  
 
      GridEditableItem editedItem = e.Item as GridEditableItem;  
 
      // get the edited values, newValues will contain the data entered in the fields in key/value pairs  
      Hashtable newValues = new Hashtable();  
      e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);  
 
      if (newValues["TIME_IN"] == null)  
      {  
        bHasErrors = true;  
        // blErrorList is a bulleted list with visable = false used to display errors  
        blErrorList.Items.Add("Time In is required.");  
      }  
 
      // save the record if no errors  
      if (!bHasErrors)  
      {  
        //save to db  
      }  
      else 
      {  
        blErrorList.Visible = true;  
        e.Canceled = true;  
      }  
}  
        
 

The InsertCommand is the same except for the very beginning of the code block....

    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)  
    {  
      bool bHasErrors = false;  
      ResetErrorSummary();  
 
      GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem;  
 
      // get the edited values  
      Hashtable newValues = new Hashtable();  
      e.Item.OwnerTableView.ExtractValuesFromItem(newValues, insertedItem);  
......  


0
Syed
Top achievements
Rank 1
answered on 19 Jun 2009, 09:17 PM
thanks
Tags
Grid
Asked by
Syed
Top achievements
Rank 1
Answers by
Curtis
Top achievements
Rank 1
Syed
Top achievements
Rank 1
Share this question
or