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

[Solved] Find control in an edit form template during itemCommand event

3 Answers 610 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kirk Thomas
Top achievements
Rank 1
Kirk Thomas asked on 08 Oct 2009, 08:37 PM
Hello,

I have a grid and with a from template for editing.  I need to be able to find the controls in the form template  in either the itemCommand event or editCommand event.  I can find them if I use if(e.CommandName == RadGrid1.UpdateCommandName) but if I try to find a contol inside the itemCommand event without any if statment like that I get a null reference exception.  I assume this is because the controls have not rendered at the time I try to find them.  What do I have to do to be able to find the controls when the edit form template is loaded?

Thanks,
Kirk

3 Answers, 1 is accepted

Sort by
0
Thomas Salt
Top achievements
Rank 1
answered on 08 Oct 2009, 08:40 PM
you can get them in the item data bound event if you need to reference them when they are loading...
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Oct 2009, 05:00 AM
Hello Kirk,

Since the EditCommand is too early to access the edit form items, you can access the items in the ItemDataBound event of the grid instead as suggested by Thomas after checking if the grid item is in edit mode. Here is an example:
c#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            TextBox txtbx1 = (TextBox)editItem["BoundColumnUniqueName"].Controls[0]; 
             
        } 
    } 

Thanks
Princy.
0
Kirk Thomas
Top achievements
Rank 1
answered on 09 Oct 2009, 02:56 PM
Thanks Thomas and Princy that did the trick.
Tags
Grid
Asked by
Kirk Thomas
Top achievements
Rank 1
Answers by
Thomas Salt
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Kirk Thomas
Top achievements
Rank 1
Share this question
or