FindControl GridTemplateColumn Outside of radGrid Events

user482375 picture user482375 · Nov 3, 2011 · Viewed 12k times · Source

I have my own method and I am trying to findcontrol on a control inside the GridTemplateColumn, so I am doing it outside of the events for the radGrid. Is this possible and if so, how?

Thanks!

Answer

Jayesh Goyani picture Jayesh Goyani · Nov 8, 2011

Try with below code.

 <telerik:GridTemplateColumn>
            <ItemTemplate>
                <asp:Label ID="Label1"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1"></asp:TextBox>
            </EditItemTemplate>
           </telerik:GridTemplateColumn>

...................

button1_click()
{
     // for Normal mode
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        Label Label1 = item.FindControl("Label1") as Label;
    }

    // for edit mode
    foreach (GridDataItem item in RadGrid1.EditItems)
    {
        TextBox TextBox1 = item.FindControl("TextBox") as TextBox;
    }
}

Thanks, Jayesh Goyani