I can't seem to bind data to a drop down tree.
Markup:
Code Behind:
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?
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 listgradeTree.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?
6 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 17 Apr 2014, 06:27 AM
Hi Mike,
Please have a look into the sample code snippet which works fine at my end.
ASPX:
C#:
Let me know if you have any concern.
Thanks,
Shinu.
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.
0
Mike
Top achievements
Rank 1
answered on 22 Apr 2014, 11:11 PM
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:
Code Behind:
Markup:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><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(); } } }}0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2014, 04:56 AM
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.
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.
0
Mike
Top achievements
Rank 1
answered on 23 Apr 2014, 09:16 PM
Unfortunately, everything I try doesn't seem to work.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Apr 2014, 02:36 AM
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.
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.
0
Mike
Top achievements
Rank 1
answered on 28 Apr 2014, 11:13 PM
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!
Thanks!