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

Treeview databind to LINQ

1 Answer 134 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Naupad
Top achievements
Rank 1
Naupad asked on 30 Jan 2012, 05:34 PM
I have Sql Database and I want to bind it through LINQ from code-behind programmatically in C#.NET. How can I do that?

I have the following code written:

public void populatetree()
    {

        using (DataClasses1DataContext db = new DataClasses1DataContext())
        {
            MsgType mt=new MsgType();
            RadTreeView1.DataFieldParentID = mt.ParentID.ToString();
            RadTreeView1.DataFieldID = mt.ID.ToString();
            RadTreeView1.DataValueField = mt.ID.ToString();
            RadTreeView1.DataTextField = mt.Name;
            RadTreeView1.ToolTip = mt.Description;
           RadTreeView1.DataSource= ?
   
            RadTreeView1.DataBind();
            
        }
    }
what shud I do for the datasource?

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 31 Jan 2012, 08:28 PM
Naupad:

Take a look at the Treeview Datasource for Linq to Entities versus a SQL Command in Code-Behind versus Code-In-Front blog post. The third example, although in VB.NET may be some help here as it populates a RadTreeView. Also, reference the Using Three Flavors of LINQ To Populate a TreeView post, as it provides insights into using LINQ with an ASP.NET Treeview.

I'm working on a simple demo and will post it when done.

Regards,
Tags
TreeView
Asked by
Naupad
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or