Use DataTable as datasource?

2 posts, 0 answers
  1. Pierre
    Pierre avatar
    260 posts
    Member since:
    Apr 2007

    Posted 27 Nov 2009 Link to this post

    I try to use a custom DataTable for the datasource. But i got no error, but nothing are displayed.

        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
            Dim dtTable As New DataTable  
            Dim dtRow As DataRow  
            dtTable.Columns.Add(New DataColumn("ID", System.Type.GetType("System.Int32")))  
            dtTable.Columns.Add(New DataColumn("Title", System.Type.GetType("System.String")))  
            dtTable.Columns.Add(New DataColumn("URL", System.Type.GetType("System.String")))  
            dtTable.Columns.Add(New DataColumn("ParentID", System.Type.GetType("System.Int32")))  
            dtTable.TableName = "SiteMap" 
            dtRow = dtTable.NewRow  
            dtRow.Item("ID") = 1  
            dtRow.Item("Title") = "Entreprise" 
            dtRow.Item("URL") = System.DBNull.Value  
            dtRow.Item("ParentID") = System.DBNull.Value  
            dtRow = dtTable.NewRow  
            dtRow.Item("ID") = 2  
            dtRow.Item("Title") = "Test" 
            dtRow.Item("URL") = "" 
            dtRow.Item("ParentID") = 1  
            SiteMap1.DataSource = dtTable  
        End Sub 

        <telerik:RadSiteMap runat="server" ID="SiteMap1"  Skin="WebBlue" 
            ShowNodeLines="true" MaxDataBindDepth="2" DataFieldID="ID" DataFieldParentID="ParentID" DataTextField="Title" > 
                <telerik:SiteMapLevelSetting Level="0">  
                    <ListLayout RepeatColumns="3" AlignRows="true" /> 

    any suggestion?
  2. Paul
    Paul avatar
    4281 posts

    Posted 27 Nov 2009 Link to this post

    Hello Pierre,

    You should call DataBind() method at the end, i.e.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dtTable As New DataTable
        Dim dtRow As DataRow
        dtTable.Columns.Add(New DataColumn("ID", System.Type.GetType("System.Int32")))
        dtTable.Columns.Add(New DataColumn("Title", System.Type.GetType("System.String")))
        dtTable.Columns.Add(New DataColumn("URL", System.Type.GetType("System.String")))
        dtTable.Columns.Add(New DataColumn("ParentID", System.Type.GetType("System.Int32")))
        dtTable.TableName = "SiteMap"
        dtRow = dtTable.NewRow
        dtRow.Item("ID") = 1
        dtRow.Item("Title") = "Entreprise"
        dtRow.Item("URL") = System.DBNull.Value
        dtRow.Item("ParentID") = System.DBNull.Value
        dtRow = dtTable.NewRow
        dtRow.Item("ID") = 2
        dtRow.Item("Title") = "Test"
        dtRow.Item("URL") = ""
        dtRow.Item("ParentID") = 1
        SiteMap1.DataSource = dtTable
    End Sub

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top