DataBinding Drop Down Tree

7 posts, 1 answers
  1. Mike
    Mike avatar
    74 posts
    Member since:
    Mar 2013

    Posted 16 Apr 2014 Link to this post

    I can't seem to bind data to a drop down tree.

    Markup:
    <telerik:RadDropDownTree runat="server" ID="radGrades" DefaultMessage="Grade"></telerik:RadDropDownTree>

    Code Behind:
    RadDropDownTree gradeTree = item.FindControl("radGrades") as RadDropDownTree;
    var grades = Grade.GetVGradeTypes();  //returns List<v_grade_type>, 6 items in list
    gradeTree.Entries.Clear();
    gradeTree.DataFieldID = "grade_id";
    gradeTree.DataFieldParentID = "grade_type_id";
    gradeTree.DataTextField = "grade";
    gradeTree.DataSource = grades;
    gradeTree.DataBind();

    I should also note, this is being called from the "ItemDataBound" event on a RadGrid [adding a new item, haven't looked at editing an existing item].  The markup lives in the EditFormTemplate of the grid. 
    Any ideas?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Apr 2014 in reply to Mike Link to this post

    Hi Mike,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadGrid ID="radgrdOrders" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" OnItemDataBound="radgrdOrders_ItemDataBound">
        <MasterTableView DataKeyNames="OrderID">
            <Columns>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <telerik:RadDropDownTree runat="server" ID="radGrades" DefaultMessage="Grade">
                    </telerik:RadDropDownTree>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void radgrdOrders_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem item = e.Item as GridEditFormItem;
            RadDropDownTree TreeGrades = (RadDropDownTree)item.FindControl("radGrades");
            TreeGrades.DataSourceID = "SqlDataSource2";
            TreeGrades.DataTextField = "text";
            TreeGrades.DataValueField = "id";
            TreeGrades.DataFieldID = "id";
            TreeGrades.DataFieldParentID = "parentid";
            TreeGrades.DataBind();
        }
    }

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    74 posts
    Member since:
    Mar 2013

    Posted 22 Apr 2014 Link to this post

    Sorry for the late reply.  I created a test page, and the drop down is still not populating with anything.  I've attached a screenshot of the issue and here is my code.

    Markup:
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <telerik:RadScriptManager runat="server" ID="radScriptManager"></telerik:RadScriptManager>
                <telerik:RadGrid ID="radgrdOrders" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" OnItemDataBound="radgrdOrders_ItemDataBound">
                    <MasterTableView DataKeyNames="grade_id">
                        <Columns>
                            <telerik:GridEditCommandColumn>
                            </telerik:GridEditCommandColumn>
                            <telerik:GridBoundColumn DataField="grade_id" UniqueName="GradeID" HeaderText="Grade ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="grade_type_id" UniqueName="GradeTypeID" HeaderText="Grade Type ID">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <telerik:RadDropDownTree runat="server" ID="radGrades" DefaultMessage="Grade">
                                </telerik:RadDropDownTree>
                            </FormTemplate>
                        </EditFormSettings>
                    </MasterTableView>
                </telerik:RadGrid>
                <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="Integrated Security=SSPI;Data Source=vosql;Initial Catalog=pqc_dev;"
                    SelectCommand="select * from defect.grade"></asp:SqlDataSource>
                <asp:SqlDataSource runat="server" ID="SqlDataSource2" ConnectionString="Integrated Security=SSPI;Data Source=vosql;Initial Catalog=pqc_dev;"
                    SelectCommand="select * from defect.v_grade_grade_type"></asp:SqlDataSource>
            </div>
        </form>
    </body>
    </html>

    Code Behind:
    using System;
    using pqc.web.Classes;
    using Telerik.Web.UI;
     
    namespace pqc.web
    {
      public partial class test : PageBase
      {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        protected void radgrdOrders_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
          if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
          {
            GridEditFormItem item = e.Item as GridEditFormItem;
            RadDropDownTree TreeGrades = (RadDropDownTree)item.FindControl("radGrades");
            TreeGrades.DataSourceID = "SqlDataSource2";
            TreeGrades.DataTextField = "grade";
            TreeGrades.DataValueField = "grade_id";
            TreeGrades.DataFieldID = "grade_id";
            TreeGrades.DataFieldParentID = "grade_type_id";
            TreeGrades.DataBind();
          }
        }
      }
    }


  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Apr 2014 in reply to Mike Link to this post

    Hi Mike,

    Unfortunately I couldn't replicate the issue at my end. Please have a look into this online demo and try to replicate the issue in this demo.

    Thanks,
    Shinu.
  6. Mike
    Mike avatar
    74 posts
    Member since:
    Mar 2013

    Posted 23 Apr 2014 in reply to Shinu Link to this post

    Unfortunately, everything I try doesn't seem to work.
  7. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2014 in reply to Mike Link to this post

    Hi Mike,

    Please have a look into the sample project which works fine at my end. The provided code is working fine at my end. Please try this sample code and let me know whether it is working at your end.

    Thanks,
    Shinu.
  8. Mike
    Mike avatar
    74 posts
    Member since:
    Mar 2013

    Posted 28 Apr 2014 Link to this post

    Well, I think I solved my issue (thanks for the demo project).  I didn't realize that the data all has to reference itself at some level.  I had to create a dummy note for the top most parent, and then have each Grade_Type point to it.  I also had to build composite ID's to guarantee uniqueness for each item.

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