RadGrid for ASP.NET

Binding to SubObjects Send comments on this topic.
Populating the control with data > Binding to SubObjects

Glossary Item Box

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 out-of-the-box binding to subobjects by the intuitive and simple dot(.) syntax (specified through the DataField property of declaratively bound columns):

Note that you may need to set RetrieveNullAsDBNull="true" for the MasterTableView in order avoid binding problems.
ASPX/ASCX Copy Code
<rad:GridBoundColumn DataField="Inner1.TestProp" HeaderText="Inner1.TestProp" >
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="Inner1.Inner2.TestProp"
HeaderText="Inner1.Inner2.TestProp">
</
rad:GridBoundColumn>
<
rad:GridBoundColumn DataField="Inner1.Inner2.Inner1.TestProp" HeaderText="Inner1.Inner2.Inner1.TestProp">
</
rad:GridBoundColumn>

And in the code-behind:

C# Copy Code
protected void RadGrid3_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
{
           ArrayList list =
new ArrayList();
           list.Add(
new MyObj("1"));
           list.Add(
new MyObj("2"));
           list.Add(
new MyObj("3"));
           list.Add(
new MyObj("4"));
           list.Add(
new MyObj("1"));

           
this.RadGrid3.DataSource = list;
}
public class MyObj
{
        
public string _innerText = "";

        
public MyObj()
       {
       }

        
public MyObj(string text)
       {
           _innerText = text;
       }

        
public MyObj Inner1
       {
            get
           {
                
return new MyObj(this._innerText + "Inner1");
           }
       }

        
public MyObj Inner2
       {
            get
           {
                
return new MyObj(this._innerText + "Inner2");
           }
       }

        
public string TestProp
       {
            get
           {
                
return this._innerText;
           }
       }
   }
}
Copy Code
VB.NET
Private Sub RadGrid3_NeedDataSource(ByVal source As Object, ByVal e As WebControls.GridNeedDataSourceEventArgs) Handles RadGrid3.NeedDataSource
             Dim list As New ArrayList
            list.Add( New MyObj("1"))
            list.Add( New MyObj("2"))
            list.Add( New MyObj("3"))
            list.Add( New MyObj("4"))
            list.Add( New MyObj("1"))

             Me.RadGrid3.DataSource = CType(list, IEnumerable)
End Sub

Public Class MyObj
         Public innerText As String = ""

         Public Sub New()
         End Sub

         Public Sub New(ByVal text As String)
             Me.innerText = text
         End Sub


         Public ReadOnly Property Inner1() As MyObj
             Get
                 Return New MyObj(Me.innerText + "Inner1")
             End Get
         End Property

         Public ReadOnly Property Inner2() As MyObj
             Get
                 Return New MyObj(Me.innerText + "Inner2")
             End Get
         End Property

         Public ReadOnly Property TestProp() As String
             Get
                 Return Me.innerText
             End Get
         End Property

 End Class



Here is an online example which represents these features:

http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/Binding/DefaultCS.aspx