Spread ASP.NET 17
Spread for ASP.NET 17 Product Documentation / Developer's Guide / Managing Data Binding / Binding to a Data Source
In This Topic
    Binding to a Data Source
    In This Topic

    The following instructions provide the code necessary to bind the FpSpread component to a data set.

    The basic procedure is to bind data either to the sheet directly or to a data model that the sheet uses. This means either using the DefaultSheetDataModel class to construct a data model and then in the SheetView class set the DataModel property to the newly created data model or setting the DataSource member in the SheetView class.

    • How you handle state management while bound to a database or working with large data sets can affect your application’s performance. You need to set up state management to optimize performance and account for other factors. For more information, refer to Maintaining State.
    • If your data set is not getting updated when you click the Update button, see the information and instructions in Limiting Postbacks When Updating Bound Data to make sure that you have code in your page load event so that you only re-create the bound data when you are loading for the first time and not overwriting it on each post back.

    Using Code

    1. Create a data model and set it equal to a DefaultSheetDataModel object, specifying a data set for the new model’s dataSource parameter.

      Other parameter options are available for the DefaultSheetDataModel constructor. Refer to the Assembly Reference for complete information.

    2. Set the SheetView object’s DataModel property equal to the new data model.

    Example

    This example code binds the FpSpread component to a data set named dataSet1.

    C#
    Copy Code
    // Create a data model using a data set.
    FarPoint.Web.Spread.Model.DefaultSheetDataModel model = new FarPoint.Web.Spread.Model.DefaultSheetDataModel(dataSet1);
    FpSpread1.Sheets[0].DataModel = model; 
    
    VB
    Copy Code
    ' Create a data model using a data set.
    Dim model As New FarPoint.Web.Spread.Model.DefaultSheetDataModel(dataSet1)
    FpSpread1.Sheets(0).DataModel = model 
    

    Using a Shortcut

    Set the FpSpread DataSource property.

    Example

    This example code uses the FpSpread DataSource property to bind to a data set.

    C#
    Copy Code
    FpSpread1.DataSource = ds; 
    
    VB
    Copy Code
    FpSpread1.DataSource = ds 
    
    See Also