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

GridAttachmentColumn Validation

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 10 Sep 2012, 08:19 AM
Hi,

I'm following the GridAttachmentColumn demo and saving to the database - all works well, but in the demo, if no file is uploaded the error message is added like so:-

  RadGrid1.Controls.Add(New LiteralControl("<b style='color:red;'>No file uploaded. Action canceled.</b>"))

This puts the message right at the bottom of the grid - is there a way to show it within the auto generated edit form please?

Also, I did look but is there an example of the GridAttachmentColumn using an edit form template?

Cheers,

Jon

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 13 Sep 2012, 08:43 AM
Hello Jon,

Maybe you have noticed that this notification is just a LiteralControl added to the Grid's controls collection on the ItemCommand event. You can use the exact same approach, but add the LiteralControl to a control of your choice. Using the demo example here is how to move it just bellow the Update/Cancel buttons:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.UpdateCommandName ||
        e.CommandName == RadGrid.PerformInsertCommandName)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        ....
 
        if (fileData.Length == 0 || fileName.Trim() == string.Empty)
        {
            e.Canceled = true;
            item.FindControl("CancelButton").Parent.Controls.Add(new LiteralControl("<br/><b style='color:red;'>No file uploaded. Action canceled.</b>"));
            //RadGrid1.Controls.Add(new LiteralControl("<b style='color:red;'>No file uploaded. Action canceled.</b>"));
        }
 
        .....
    }
}

Another approach you can follow is to add validator controls to your edit form. More information on the matter is available in the help article bellow:

Validation

As to your second question - the FormTemplate edit form type supposes that developers want to have a complete control over the Edit Form content. Based on that the GridAttachmentColumn would not render any content in the edit form. Instead the form would contain what the developer have provided in the FormTemplate property of the TableView.

I hope this helps.

All the best,
Martin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or