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

Dynimcally Add DropDownList to radGrid ItemTemplate

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 03 Nov 2011, 01:18 AM
I am trying to add Dropdownlist to each row of a radGrid in the ItemTemplate dynamically. So basically when the radGrid loads I want to add DropDOwnList to each row and add certain data to it based on the id created. How would I go about doing that?


Thanks!

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Nov 2011, 04:59 AM
Hello Justin,

Try the following code snippet in ItemDataBound event.

C#:
protected void grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
     GridDataItem dataitem = (GridDataItem)e.Item;
     TableCell cell = dataitem["TemplateColumnUniqueName"];
     DropDownList ddl = new DropDownList();
     ddl.ID = "ddl";
     ddl.DataSourceID = "SqlDataSource1";
     ddl.DataTextField = "EmployeeID";
     ddl.DataValueField = "EmployeeID";
     cell.Controls.Add(ddl);
  }
}

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