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

find the type of control in template column

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 15 Nov 2013, 03:39 AM
Hi,
We are using radgrid latest version. We have a global routine used to loop thru rows of grid. THis is used in multiple page. On some page, grid has templated column with textbox and on other pages, grid tempate column has checkboxes. So, when grid is passed to global routine and loop thru rows, I need to check for templated column control type. If it is checkbox, I need to do some logic and if it is textbox, I need to do some other logic. Please let me know how to write code. FindControl expects ID. I know the id of both controls, but I don't know which one to use.
Something similar this

 

 

foreach (GridDataItem row in radGrid1.Items)
{
   //get the type of control
   Control ctl = typeof(row.findcontrol(...);
   if typeof(ctl) is Checkbox
    //do something
   if type(ctl) is TextBox
     //do something else.
}

This logic needs to be in global routine outside radgrid events.
Thank You

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Nov 2013, 05:11 AM
Hi Prathibarani,

Please try the following code snippet to find the type of control in Template column. I have used a button which is outside the RadGrid to access the controls.

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    string value, ColType, Id  ;
    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)
                {
                     ColType = control.GetType().Name;
                     Id = control.ID;
                    if (ColType.Equals("CheckBox"))
                    {
                     value = ((CheckBox)(control)).Checked.ToString();                         
                    }
                    if (ColType.Equals("TextBox"))
                    {
                     value = ((TextBox)(control)).Text;                         
                    }
                }
            }
        }
    }
}

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