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

[Solved] How to find User Control

1 Answer 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 03 Apr 2009, 10:03 PM

My RadGrid uses a user control for its editing, and because that user control is also used outside of a RadGrid (in a FormView), I'm running into a problem.  I could resolve it if I could locate (using FindControl?) the user control inside the RadGrid.

  • Both the RadGrid and the FormView / ObjectDataSource call a method for the update, and that business object expects an object whose properties match the fields in the database. 
  • The user control contains a LinkButton to fire the update process.

 

If I was using only the RadGrid, I'd add code to the ItemCommand event, determine that it was the update event firing (because the CommandName of the LinkButton would be "Update"), find my user control by calling e.Item.FindControl(GridEditFormItem.EditFormUserControlID), and I'd be on my way.

If I was only using the FormView, I'd change the CommandName of the LinkButton to something OTHER THAN Update (so I could avoid the object data source from trying to do the update), respond to the command in the FormView's ItemCommand event, and find my user control  by calling myFormView.FindControl(<the user control's ID>).

Here's the problem:
To keep the object data source from trying to do the update, I have to set the CommandName of the LinkButton to something other than "Update".  If I set the CommandName of the LinkButton to something other than "Update", I don't get a GridEditFormItem in the RadGrid's ItemCommand event, I get a GridDataItem - and no way to get to the user control.

How do I locate the user control used by a RadGrid?

Thanks,
    Ben
(please respond to ben.furino@bolderimage.com)

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 07 Apr 2009, 06:55 AM
Hello Ben,

You can access the user control through the GridDataItem object:

((Telerik.Web.UI.GridDataItem)(e.Item)).EditFormItem.FindControl("NameOfYourUserControl"

I hope this helps.

Kind regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or