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

get reference to control in GridTemplateColumn

1 Answer 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kellyroberts
Top achievements
Rank 1
kellyroberts asked on 12 Jul 2012, 09:32 PM

Trying to access an <asp:dropdownlist> from <telerik:GridTemplateColumn> in the ItemCommand event of a RadGrid. 

 

 

BarID is the unique column name on the template column
ddlBarID is the id of the dropdownload

GridEditFormItem editedItem = (GridEditFormItem)((GridDataItem)e.Item).EditFormItem;
DropDownList ddlBar = 
(DropDownList)editedItem["BarID"].FindControl("ddlBarID");
Label1.Text = "BarID null: " + (ddlBar == null).ToString();
ddlBar.Items.Add("TEST");

 

 

I get Object reference not set to an instance of an object.


any help is appreciated.  been banging my head on this one for two days now.

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Jul 2012, 04:27 AM
Hello,

Here is the sample that I tried which worked as expected.
C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
 if (e.CommandName == "commandname")
 {
   GridEditableItem editedItem = (GridEditableItem)e.Item;
   DropDownList ddl = (DropDownList)((Telerik.Web.UI.GridDataItem)(editedItem)).EditFormItem.FindControl("DropDownList1");
 }
}

Thanks,
Shinu.
Tags
Grid
Asked by
kellyroberts
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or