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

[Solved] Loop thru cells or controls in templated column

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 03 May 2013, 10:33 PM
Hi,

My grid has Item Template column with controls. This kind of requirement is on many pages. Some pages have label and textbox in template column. other pages have radio button list or dropdown list. What I am trying to do is write global code to iterate through template column controls and enable or disable them.

Something like this:

private void EnableTemplateContrils(GridTemplateColumn tmpCol)
{
        bool status = false;

    foreach (cell or control in tmpCol)
   {
       enableORDisableControl(control, status);
   }
}

private void enableORDisableControl(System.Web.UI.Control pControl, bool pStatus)
{
    string controlName = pControl.GetType().Name;
    switch(controlName)
     {
         case "TextBox":
                ((WebControl)pControl).enabled = pStatus;
                break;
         case "CheckBox":

     }
}

I appreciate your response. Please let me know how to loop thru controls in template column.

Thanks,
Prathiba

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 May 2013, 10:22 AM
Hello,

foreach (GridColumn column in RadGrid1.Columns)
        {
            if (column.GetType().Name == "GridTemplateColumn")
            {
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                {
                    foreach (Control control in item[column.UniqueName].Controls)
                    {
                        enableORDisableControl(control, true);
                    }
                }
            }
        }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or