get reference to control in GridTemplateColumn

2 posts, 0 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 12 Jul 2012 Link to this post

    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.

     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Jul 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top