Conditionally change UpdateCommand if no file is selected

Thread is closed for posting
4 posts, 0 answers
  1. james fang
    james fang avatar
    10 posts
    Member since:
    Aug 2009

    Posted 01 Oct 2010 Link to this post

    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.
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 04 Oct 2010 Link to this post

    Hello James,

    How are you adding the validator to the Grid? In the EditTemplate or from code-behind?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. james fang
    james fang avatar
    10 posts
    Member since:
    Aug 2009

    Posted 04 Oct 2010 Link to this post

    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. 
  5. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 06 Oct 2010 Link to this post

    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.
Back to Top