# Bind Data Set and Unbound Data to Section Report at Run Time

This topic explains how to bind data set and unbound data to a section report at run time.

## Content



A Section report allows to specify a data set and unbound data, using a similar API. You need to just specify DataSet, DataTable, DataView, RowCollection as shown in the [DataSource](/activereportsnet/api/v19.2/MESCIUS.ActiveReports/GrapeCity.ActiveReports.SectionReport.html#DATASOURCE) property. For DataSet, you should specify it as shown in the [DataMember](/activereportsnet/api/v19.2/MESCIUS.ActiveReports/GrapeCity.ActiveReports.SectionReport.html#DATAMEMBER) property.

In addition, a Section report allows to use any unbound data as a data source with the following script logic:

## To use the IEnumerable data source

1.  Right-click the design surface and select View Code.
2.  Add the following code inside the class declaration of the report:
    
    ```vbnet
    Private datasource1 As IEnumerator(Of String) = Nothing 
    Dim list As List(Of String)= Nothing
    ```
    
    ```vbnet
    Private Function GetIEnumerableData() As IEnumerable(Of String)    
        For i As Integer = 1 To 10
           list.Add(String.Format("TestData_{0}", i.ToString()))       
        Next       
        Return list
    End Function
    ```
    
    ```csharp
    private IEnumerator<string> datasource = null;
    ```
    
    ```csharp
    private IEnumerable<string> GetIEnumerableData()
    {
        for (int i = 1; i <= 10; i++)
        {
            yield return string.Format("TestData_{0}", i.ToString());
        }
    }
    ```
    
3.  On the design surface, right-click the gray area around the design surface to select the report and select Properties.
4.  In the Properties window that appears, click the Events icon to view the available events for the report.
5.  Double-click the **DataInitialize** event. This creates an event-handling method for the report's DataInitialize event.
6.  Add the following code to the handler to add fields to the report's Fields collection.
    
    ```vbnet
    Me.Fields.Add("TestField")
    Me.list = New List(Of String)
    datasource1 = GetIEnumerableData().GetEnumerator()
    ```
    
    ```csharp
    this.Fields.Add("TestField");
    datasource = GetIEnumerableData().GetEnumerator();
    ```
    
7.  Repeat steps 3 and 4 to open the events list in the property window.
8.  Double-click the **FetchData** event. This creates an event-handling method for the report's FetchData event.
9.  Add code to the handler to retrieve information to populate the report fields.
    
    ```vbnet
    If datasource1.MoveNext() Then
                                            Me.Fields("TestField").Value = datasource1.Current
                                            eArgs.EOF = False
    Else
                                            eArgs.EOF = True
    End If
    ```
    
    ```csharp
    if (datasource.MoveNext())
    {
        this.Fields["TestField"].Value = datasource.Current;
        eArgs.EOF = false;
    }
    else
        eArgs.EOF = true;
    ```
    


> type=info
> **Tip**: In order to view the added data at run time, add controls to your report and assign their **DataField** property to the name of the fields you added in code while creating a field collection.
