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

RadGrid Simple Binding

2 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
le N
Top achievements
Rank 1
le N asked on 17 May 2010, 02:21 PM
Hi buddies!

I'm facing a little problem with the RadGrid control.

I've got a simple RadGrid:
 <telerik:RadGrid ID="RadGrid1" runat="server"   OnNeedDataSource="RadGrid1_NeedDataSource"
     
    </telerik:RadGrid> 


When i use this code eveything works and the data is well displayed :

 Protected Sub RadGrid1_NeedDataSource(ByVal [source] As Object, _ 
         ByVal e As GridNeedDataSourceEventArgs) _ 
         Handles RadGrid1.NeedDataSource 
        Dim list As New ArrayList 
        list.Add("string1") 
        list.Add("string2") 
        list.Add("string3") 
        RadGrid1.DataSource = list 
 
     
 
    End Sub 
But when i try to use a custom class (Acontact) this is the class :

Public Class AContact 
    Private _name As String 
    Private _email As String 
 
 
 
 
    Public Property Name() As String 
        Get 
            Return _name 
        End Get 
        Set(ByVal value As String) 
            _name = Name 
        End Set 
    End Property 
 
    Public Property Email() As String 
        Get 
            Return _email 
        End Get 
        Set(ByVal value As String) 
            _email = Email 
        End Set 
    End Property 
 
 
 
 
End Class 

i try this, but the grid stays empty:

Protected Sub RadGrid1_NeedDataSource(ByVal [source] As Object, _ 
         ByVal e As GridNeedDataSourceEventArgs) _ 
         Handles RadGrid1.NeedDataSource 
        
 
        Dim maListe As New List(Of SABerni.Gateway.AContact) 
 
 
        Dim Contact1 As New SABerni.Gateway.AContact 
        Contact1.Name = "demo" 
        Contact1.Email = "emaildemo" 
 
        maListe.Add(Contact1) 
 
 
        RadGrid1.DataSource = maListe 
 
    End Sub 

Does anybody have an idea? Thanks a lot..

Nicolas







2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 17 May 2010, 03:41 PM
Hello Nicolas,

Actually RadGrid binds to the collection, but the cells for the items will remain empty. This is due to the fact that the properties for the class AContact are not correctly implemented. Correct implementations should look as bellow:

01.Public Class AContact
02.        Private _name As String
03.        Private _email As String
04.        Public Property Name() As String
05.            Get
06.                Return _name
07.            End Get
08.            Set(ByVal value As String)
09.                _name = value
10.            End Set
11.        End Property
12.    
13.        Public Property Email() As String
14.            Get
15.                Return _email
16.            End Get
17.            Set(ByVal value As String)
18.                _email = value
19.            End Set
20.        End Property
21.    End Class


Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
le N
Top achievements
Rank 1
answered on 17 May 2010, 03:50 PM
oh oh oh, how stupid i am..Sorry! indeed it works better!!

Thank you.
Tags
Grid
Asked by
le N
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
le N
Top achievements
Rank 1
Share this question
or