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

This cant be that hard

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 03 Dec 2011, 10:27 PM
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"); 
OR
DropDownList ddl = (DropDownList)dataItem["Status"].Controls[0]
ddl.DataSource = _WhatEver; <=== ddl is null

J

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Dec 2011, 04:49 AM
Hello,

GridDropDownColumn is rendered in edit mode. You can populate the DropDown in edit mode as shown below.
C#:
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;
  }
}

-Shinu.
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or