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

Conditionally change UpdateCommand if no file is selected

3 Answers 111 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
james fang
Top achievements
Rank 1
james fang asked on 02 Oct 2010, 01:59 AM
I'm looking at the demo 'Binary Images and Upload in Grid'.  While in edit mode, if no file is selected, the validator will display "Please select file to be uploaded".  What is the work around so that the UpdateCommand simply won't include the binaryimage field in the update?  I'm really new to .Net and Telerik so I'll appreciate some sample code if possible.  I just figure when user edits a record, if he doesn't select any new file to upload, I'd like to still update the rest of the record and leave the image field unchanged instead of forcing user to select a new file.  I can't think of a way to do so.  Any help would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 04 Oct 2010, 03:01 PM
Hello James,

How are you adding the validator to the Grid? In the EditTemplate or from code-behind?
0
james fang
Top achievements
Rank 1
answered on 04 Oct 2010, 06:55 PM
I was doing exactly as shown in the BinaryImage demo (http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=binaryimage).  The validator is in the code behind while UpdateCommand is in the markup.  You can see in the live demo right now that if you select any file while editing a record, it won't let you update. 
0
Cori
Top achievements
Rank 2
answered on 06 Oct 2010, 02:34 PM
Hello James,

Change the if statement to something like this:

if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.IsItemInserted)
            {
                GridBinaryImageColumnEditor editor = ((GridEditableItem)e.Item).EditManager.GetColumnEditor("Upload") as GridBinaryImageColumnEditor;
                TableCell cell = (TableCell)editor.RadUploadControl.Parent;
                CustomValidator validator = new CustomValidator(); 
                validator.ErrorMessage = "Please select file to be uploaded";
                validator.ClientValidationFunction = "validateRadUpload";
                validator.Display = ValidatorDisplay.Dynamic;
                cell.Controls.Add(validator);
            }

The IsItemInserted property determines if the form is in insert mode. So now it should only add the validator when in insert mode.

Try that out and tell me if it works.
Tags
Upload (Obsolete)
Asked by
james fang
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
james fang
Top achievements
Rank 1
Share this question
or