This cant be that hard

2 posts, 0 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 03 Dec 2011 Link to this post

    I cannot seem to find an simple explanation as to how to reference a GridDropDownColumn and set its datasource in the ItemDataBound event.  I cannot figure out how to not get 'null' back for this:

    GridDataItem dataItem = (GridDataItem)e.Item;
    DropDownList ddl = (DropDownList)dataItem.FindControl("Status"); 
    DropDownList ddl = (DropDownList)dataItem["Status"].Controls[0]
    ddl.DataSource = _WhatEver; <=== ddl is null

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

    Posted 04 Dec 2011 Link to this post


    GridDropDownColumn is rendered in edit mode. You can populate the DropDown in edit mode as shown below.
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
      if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       GridEditableItem item = (GridEditableItem)e.Item;
       DropDownList ddl = (DropDownList)item["Status"].Controls[0];
       ddl.DataSourceID = "SqlDataSource1;

Back to Top