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

[Solved] Treeview using Entity Framework

5 Answers 170 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Howard
Top achievements
Rank 1
Howard asked on 24 Jan 2012, 02:50 AM
Hi Support,

I am trying to make a treeview similar to "Binding to Model" but i am using entity framework.

Could you please send me sample example related to showing data using entity framework for Treeview.

Regards

5 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 25 Jan 2012, 11:29 AM
Hello Niroj,

 Providing custom samples by request is out of our support services scope, but if you send us a sample project that shows your current setup, what you have done so far and what exactly is the problem that you experience, we will check it and suggest a solution.

All the best,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Howard
Top achievements
Rank 1
answered on 30 Jan 2012, 04:10 AM

 

 

 

 

Hi Georgi,

My code is below to display on Treeview but it's not working.
Could you please suggest what could be the solution

//Model
namespace AusFleet.Data.Models.ReferenceFile
{

 public

 class PFLModelModel

     {

 

 

    public int MODEL_ID { get; set; }     
     public
string MODEL_USER_CODE { get; set; }

     public string MODEL_DESCRIPTION { get; set; }
    }
public class PFLSeriesModel  

    {

     public int SERIE_ID { get; set; }

     public string SERIE_USER_CODE { get; set; }

         public int? MODEL_ID { get; set; }

        public string SERIE_DESCRIPTION { get; set; }
    }
}

// Controller

 public ActionResult DataBindingToModel()
{
ReferencesFiles _ReferencesFiles = new ReferencesFiles();
var _pFLModel = _ReferencesFiles.Model();
return PartialView("_PFLModel", _pFLModel);

 }

//PartialView _PFLModel

 

@(Html.Telerik().TreeView()

.Name("TreeView")

 .BindTo(Model, mappings =>

 {

mappings.For<PFLModelModel>(binding => binding

.ItemDataBound((item, category) =>

    {

    item.Text = category.MODEL_DESCRIPTION;

    })

    .Children(category => category.SERIE_ID));

mappings.For<PFLSeriesModel>(binding => binding

    .ItemDataBound((item, product) =>

    {

    item.Text = product.SERIE_DESCRIPTION;

        }));

    })

 )

 

 

 

0
Georgi Tunev
Telerik team
answered on 30 Jan 2012, 04:01 PM
Hello Niroj,

The code that you provided does not show what is the relation between the two classes. What I see is that you set .Children(category => category.SERIE_ID));. This however, should be a collection of items, not an integer as it is set in your PFLSeriesModel class.


All the best,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Howard
Top achievements
Rank 1
answered on 31 Jan 2012, 06:09 AM
Hi Georgi,

MODEL_ID in PFLModelModel is the foreign key in PFLSeriesModel. Connecting this to table i want to show the treeview structure as every MODEL_DESCRIPTION has its Sub node as SERIES_DESCRIPTION.

Regards
0
Georgi Tunev
Telerik team
answered on 03 Feb 2012, 10:18 AM
Hello again Niroj,

As I noted in my previous reply, the problem is that you pass an integer to the children collection while you should feed it with a collection of items. There are various resources in the Web that show how to use self-referencing binding (by the way, the Drag and Drop Treeview's demo also uses self-referencing binding)


Regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
TreeView
Asked by
Howard
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Howard
Top achievements
Rank 1
Share this question
or