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

how to bind DropDownList in template column

4 Answers 175 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Kushal
Top achievements
Rank 1
Kushal asked on 08 Nov 2011, 06:30 AM
I have a dropdownlist in EditItemTemplate / insertItemTEmplate and in the codebehind file I am trying to bind it to a datasource.
could you please suggest how to bind it to a data source and in which event i should do it in codebehind file?

here is my radtreelist :


<telerik:TreeListTemplateColumn DataField="WorkShopType" UniqueName="WorkShopType" HeaderText="WorkShopType" >
                   
<ItemTemplate>
 <%# Eval("WorkShopType")%></ItemTemplate>
            <EditItemTemplate>
         <asp:DropDownList ID="ddlWorkShopTypeEdit" runat="server" />
                         </EditItemTemplate>
                         <InsertItemTemplate>
<asp:DropDownList ID="ddlWorkShopTypeInsert" runat="server"/>
</asp:RequiredFieldValidator></InsertItemTemplate></telerik:TreeListTemplateColumn>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Nov 2011, 07:10 AM
Hello Kushal,

You can try the following code snippet in ItemDataBound event.
C#:
protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
{
 if (e.Item is TreeListEditableItem && (e.Item as TreeListEditableItem).IsInEditMode)
  {
    TreeListEditableItem item = (TreeListEditableItem)e.Item;
    DropDownList list = (DropDownList)item.FindControl("ddlWorkShopTypeEdit");
    list.DataValueField = "OrderID";
    list.DataTextField = "OrderID";
    list.DataSourceID = "SqlDataSource2";
  }
}

Thanks,
Princy.
0
Kushal
Top achievements
Rank 1
answered on 08 Nov 2011, 09:43 AM
Thanks Princy for the response. initially I tried the similar code in databound event.
I tried the code mentioned but list variable is coming as NULL.
I checked the dropdownlist name and it is correct.
I am using editmode as editform. and I have placed treelist control inside a usercontrol. does it has anythign to do with it?

Even I am not able to see the dropdownlist name in the rendered html in browser.

Am I missing anything?



0
Princy
Top achievements
Rank 2
answered on 09 Nov 2011, 07:08 AM
Hello Kushal,

Try the following code snippet.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
  RadTreeList tree = (RadTreeList)UserControl1.FindControl("RadTreeList1");
  tree.ItemDataBound += new EventHandler<TreeListItemDataBoundEventArgs>(tree_ItemDataBound);
}
void tree_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
{
  if (e.Item is TreeListEditableItem && (e.Item as TreeListEditableItem).IsInEditMode)
  {
     TreeListEditableItem item = (TreeListEditableItem)e.Item;
     DropDownList list = (DropDownList)item.FindControl("ddlWorkShopTypeEdit");
      // bind the dropdown   
  }
}

Thanks,
Princy.
0
Kushal
Top achievements
Rank 1
answered on 10 Nov 2011, 07:40 AM
Thanks Princy.

I changed the following line to get the item and it worked for me.

TreeListEditFormItem item = e.Item as TreeListEditFormItem;

Tags
TreeList
Asked by
Kushal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kushal
Top achievements
Rank 1
Share this question
or