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

[Solved] Access controls inside Grid FormTemplate

3 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kia
Top achievements
Rank 1
Kia asked on 10 Apr 2008, 03:40 PM
Hi,

I have a rad grid using a template for formEdit. I've placed a bunch of controls and bound them to data, but I need to sed the combo box data sources from my VB code. How do I access controls inside the FormTemplate?

I tried FindControl, but I must be missing something in here(VB):

CType(Me.rgrdOrders.FindControl("cboSuppliers"), DropDownList) 

Everything I try returns "Nothing"

3 Answers, 1 is accepted

Sort by
0
alan
Top achievements
Rank 1
answered on 11 Apr 2008, 12:31 PM
Kia,

You cannot use FindControl this way. You would not be able to use it in GridView either. You have to call it on a grid item:
item.FindControl(....)
Grid items are INamingContainer - check here:

http://msdn2.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx
0
Kia
Top achievements
Rank 1
answered on 14 Apr 2008, 03:24 AM
Thanks,

I had a look at the site and I'm afraid I'm a little more confused than before looking up INamingContainer. Sorry for my lack of .Net skills.  I then tried to use e.item on EditCommand and have the same problem.

I think that in http://www.telerik.com/community/forums/thread/b311D-bbhkec.aspx, they refer to the same thing.

Can I please see a code snippet doing this?
0
alan
Top achievements
Rank 1
answered on 14 Apr 2008, 11:05 AM
Kia,

You cannot invoke RadGrid.FindControl("MyControlID") as RadGrid has many items and there could be "MyControlID" in each grid item. You have to find the edited item and call FindControl.
It could be something like this in ItemDataBound:


If TypeOf e.Item is GridEditFormItem And e.Item.IsInEditMode Then 
    Dim ddl as DropDowList = e.item.FindControl("cboSuppliers"
Endif 



Tags
Grid
Asked by
Kia
Top achievements
Rank 1
Answers by
alan
Top achievements
Rank 1
Kia
Top achievements
Rank 1
Share this question
or