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

Adding validator in template column

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Digital Man
Top achievements
Rank 2
Digital Man asked on 18 Nov 2008, 02:01 PM
I tried to submit this as a support ticket but it timed out so am posting here
----------------------------------------------------------------------------------------------------------

I can add validators to built in columns with no problem using the following code:

    protected void rgData_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;

            if (e.Item.OwnerTableView.DataMember == "Download")
            {
                GridTemplateColumnEditor edFile = (GridTemplateColumnEditor)item.EditManager.GetColumnEditor("DocumentFile");
                GridTextBoxColumnEditor edDescription = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("Description");

                edDescription.TextBoxControl.ID = "txtDescription";
                edDescription.TextBoxControl.Width = Unit.Pixel(350);

However this does not seem to work with template columns. One of my template columns contains a FileUpload control. Above you can see where I try and reference it (edFile). But when I try to access the control using

((FileUpload)edFile.FindControl("fuFile")).Width = Unit.Pixel(350);
or
((FileUpload)edFile.Controls[0]).Width = Unit.Pixel(350);

I get a null reference. I was hoping I could keep all this code in the same place (ItemCreated). But do template columns need to be handled differently? Thanks.

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 21 Nov 2008, 09:15 AM
Hi Dan Duda,

One possible option in this case is to get a reference to the editForm item. Once you do this, you can reference all the controls in it, and hence add validators, and set the controltovalidate property for the relevant validators, to point to the upload, or any other control.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
David
Top achievements
Rank 1
answered on 31 Oct 2012, 03:30 PM
Can someone give an example of this? I am looking into using a template column so that I can access two controls in a template column editor, but I have not found a way to assign the ControlToValidate.
0
Maria Ilieva
Telerik team
answered on 05 Nov 2012, 12:13 PM
Hello David,

I would suggest you to review the online demo below which presents the best approach for achieving the required validation functionality:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/validation/defaultcs.aspx

I hope this helps.

Regards,
Maria Ilieva
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
Digital Man
Top achievements
Rank 2
Answers by
Yavor
Telerik team
David
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or