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

Rad Grid and ASP Required Field Validator

4 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Soha
Top achievements
Rank 1
Soha asked on 16 Dec 2010, 03:09 PM
I am using RadGrid, containing about 15 columns. Only one of them is editable, it is a text-box and i am using asp required field validator for it.
 when i export that grid to excel or pdf, another column appears containing the text included in the required field validator even if it is already not visible on the grid.

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 16 Dec 2010, 09:42 PM
Hello Soha,

Is the RequiredFieldValidator part of the ItemTemplate for that column? That's the only way I can see it being exported.
0
Soha
Top achievements
Rank 1
answered on 16 Dec 2010, 11:18 PM
Thanks for your reply.
Yeah, actually it is.
Where else should i put it to be beside the text?
0
Princy
Top achievements
Rank 2
answered on 17 Dec 2010, 07:53 AM
Hello Soha,

One solution is to hide the RequiredFieldValidator before eporting . Sample code is given below.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                RequiredFieldValidator validator = (RequiredFieldValidator)item.FindControl("RequiredFieldValidator1");// accessing RequiredFieldValidator
                validator.Visible = false;
            }
            RadGrid1.ExportSettings.OpenInNewWindow = true;
            RadGrid1.MasterTableView.ExportToExcel();
        }
    }

Thanks,
Princy.
0
Soha
Top achievements
Rank 1
answered on 19 Dec 2010, 09:38 AM
but how shall i return it back to Visible = true after the export function finishes
Tags
Grid
Asked by
Soha
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Soha
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or