how to bind DropDownList in template column

5 posts, 0 answers
  1. Kushal
    Kushal avatar
    11 posts
    Member since:
    Sep 2011

    Posted 08 Nov 2011 Link to this post

    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>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kushal
    Kushal avatar
    11 posts
    Member since:
    Sep 2011

    Posted 08 Nov 2011 Link to this post

    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?



  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Nov 2011 Link to this post

    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.
  6. Kushal
    Kushal avatar
    11 posts
    Member since:
    Sep 2011

    Posted 10 Nov 2011 Link to this post

    Thanks Princy.

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

    TreeListEditFormItem item = e.Item as TreeListEditFormItem;

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017