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

combobox in griditemtemplate + databinding

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 09 Aug 2011, 09:21 PM
Hi, i would like to use the a combobox in the grid item template and i would like to populate the combobox with data from my db, but also do the databinding from the codebehind, is there a way to do this? 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2011, 05:09 AM
Hello Bryan,

You can try the following code snippet in ItemCreated event to populate RadComboBox from code behind.
aspx:
<telerik:GridTemplateColumn>
     <ItemTemplate>
          <telerik:RadComboBox ID="RadComboBox1" runat="server"></telerik:RadComboBox>
     </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
      GridDataItem item = (GridDataItem)e.Item;
      RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
      combo.DataSourceID = "SqlDataSource1";
      combo.DataTextField = "EmployeeID";
      combo.DataValueField = "EmployeeID";
      combo.DataBind();
  }
}

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