Databind to Linq

6 posts, 0 answers
  1. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 08 Sep 2008 Link to this post

    I am trying to bind my RadMenu to a Linq DataContext, but I think I am doing something wrong... any help is appreciated.

    ASPX
    <telerik:RadMenu ID="RadMenu1" runat="server" /> 

    ASPX.VB
            'Create DataContext  
            Dim PagesDC As New Dal.icms_PagesDataContext  
              
            'Establish the Menu  
            Dim MenuResults = PagesDC.icms_Pages_GetPageMenu()  
            RadMenu1.DataSource = MenuResults  
            RadMenu1.DataFieldID = "ID" 
            RadMenu1.DataTextField = "MenuName" 
            RadMenu1.DataFieldParentID = "ParentID" 
            RadMenu1.DataNavigateUrlField = "ID" 
            RadMenu1.DataBind() 

    Anyone know what I have done wrong?
  2. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 08 Sep 2008 Link to this post

    Also tried this without luck
            'Establish the Menu  
            Dim MenuResults = From r In PagesDC.icms_Pages_GetPageMenu() _  
                              Select r  
            RadMenu1.DataSource = MenuResults  
            RadMenu1.DataFieldID = ("ID")  
            RadMenu1.DataTextField = ("MenuName")  
            RadMenu1.DataFieldParentID = ("ParentID")  
            RadMenu1.DataNavigateUrlField = ("ID")  
            RadMenu1.DataBind() 
  3. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 09 Sep 2008 Link to this post

    Hi Chase Florell,

    I have attached a sample project demonstrating how to bind RadMenu to LINQ data context. Please have in mind that such binding is supported since our Q2 2008 SP1 release (the current official one).

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 09 Sep 2008 Link to this post

    Hello Albert
    I have followed your instructions and even though it is working in your example... it is not working in mine... I can't see what I could be missing.

    Imports System  
    Imports System.Configuration  
    Imports System.Data  
    Imports System.Linq  
    Imports System.Web  
    Imports System.Web.Security  
    Imports System.Web.UI  
    Imports System.Web.UI.HtmlControls  
    Imports System.Web.UI.WebControls  
    Imports System.Web.UI.WebControls.WebParts  
    Imports System.Xml.Linq  
    Imports System.Data.SqlClient  
    Imports Telerik.Web.UI  
    Imports RadHelper  
     
    Partial Class _Default  
        Inherits RadHelper.HelperPage  
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
     
            If Not Page.IsPostBack Then 
                'Establish the Menu  
     
                Dim db As New Dal.icms_PagesDataContext()  
     
                RadMenu1.DataTextField = "MenuName" 
                RadMenu1.DataFieldID = "ID" 
                RadMenu1.DataFieldParentID = "ParentID" 
     
                RadMenu1.DataSource = db.icms_Pages  
                RadMenu1.DataBind()  
            End If 
     
        End Sub 
    End Class 

    I have my dbml file correct
    App_Code/Dal/icms_Pages.dbml

    When the page renders the menu is blank.  I have built the app as well (i have heard that LINQ can be finniky that way) without luck.

    As far as I can see... I have done it exactly as you have... am I missing something in the web.config?

    the dll I am using is
    (2008.2.826.20)
  5. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 09 Sep 2008 Link to this post

    Also, if possible I prefer to use my Stored Procedure instead of direct DB access... just for consistancy.

    ALTER PROCEDURE dbo.icms_Pages_GetPageMenu  
     
    AS 
    SET NOCOUNT ON 
     
    Select ID,  
           ParentID,  
           MenuName  
     
    From icms_Pages 
  6. Chase Florell
    Chase Florell avatar
    257 posts
    Member since:
    Apr 2005

    Posted 09 Sep 2008 Link to this post

    BAAAAHHHH

    Ok so I solved this one on my own too.  After reading This Thread I realized that my "ParentID" column was set to "0" rather than "Null".  I changed it and the menu rendered as expected.

    ASS
    Always Something Simple.
Back to Top