You can use a wide variety of data-sources for grid structure generation (the only requirement is that these custom objects implement the ITypedList/IEnumarable/ICustomTypeDescriptor interfaces). Furthermore, Telerik RadGrid supports binding to list of custom objects with Nullable properties (.NET 2.0 feature). For more details please refer to the code snippets below:
| ASPX/ASCX |
Copy Code |
|
<rad:RadGrid id="RadGrid2" runat="server"> <MasterTableView AutoGenerateColumns="True"> </MasterTableView> </rad:RadGrid> |
And in the code-behind:
| C# |
Copy Code |
|
protected void RadGrid2_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) { ArrayList list = new ArrayList(); list.Add( new TestListItem( "Item 0", 0) ); list.Add( new TestListItem( "Item 1", 0 ) ); list.Add( new TestListItem( "Item 2", 1 ) ); list.Add( new TestListItem( "Item 3", 1 ) ); list.Add( new TestListItem("Item 4", null));
this.RadGrid2.DataSource = list; } public class TestListItem { private string _a; private int? _b;
public TestListItem( string a, int? b ) { this._a = a; this._b = b; }
public string A { get { return this._a; } set { this._a = value; } }
public int? B { get { return this._b; } } } |
| VB.NET |
Copy Code |
|
Private Sub RadGrid2_NeedDataSource(ByVal [source] As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource Dim list As New ArrayList list.Add( New TestListItem("Item 0", 0)) list.Add( New TestListItem("Item 1", 1)) list.Add( New TestListItem("Item 2", 2)) list.Add( New TestListItem("Item 3", 3)) list.Add( New TestListItem("Item 4", Nothing))
Me.RadGrid2.DataSource = CType(list, IEnumerable) End Sub Public Class TestListItem Private _a As String Private _b As Nullable(Of Integer)
Public Sub New(ByVal a As String, ByVal b As Nullable(Of Integer)) Me._a = a Me._b = b End Sub
Public Property A() As String Get Return Me._a End Get Set(ByVal Value As String) Me._a = Value End Set End Property
Public ReadOnly Property B() As Nullable(Of Integer) Get Return Me._b End Get End Property End Class End Namespace |