Intersoft WebGrid Documentation
DataSource Property
See Also  Example Send Feedback
ISNet.WebUI.WebGrid Namespace > WebGrid Class : DataSource Property






Gets or sets the data source for which the WebGrid control displays its data.

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Data")>
<DefaultValueAttribute()>
<BindableAttribute(Bindable=True, Direction=BindingDirection.OneWay)>
<DescriptionAttribute("Gets or sets the datasource of the grid")>
<DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)>
Public Overridable Property DataSource As Object
Visual Basic (Usage)Copy Code
Dim instance As WebGrid
Dim value As Object
 
instance.DataSource = value
 
value = instance.DataSource
C# 
[CategoryAttribute("Data")]
[DefaultValueAttribute()]
[BindableAttribute(Bindable=true, Direction=BindingDirection.OneWay)]
[DescriptionAttribute("Gets or sets the datasource of the grid")]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
public virtual object DataSource {get; set;}
Delphi 
public read-write property DataSource: TObject; virtual; 
JScript 
CategoryAttribute("Data")
DefaultValueAttribute()
BindableAttribute(Bindable=, Direction=BindingDirection.OneWay)
DescriptionAttribute("Gets or sets the datasource of the grid")
DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)
public function get,set DataSource : Object
Managed Extensions for C++ 
[CategoryAttribute("Data")]
[DefaultValueAttribute()]
[BindableAttribute(Bindable=true, Direction=BindingDirection.OneWay)]
[DescriptionAttribute("Gets or sets the datasource of the grid")]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
public: __property virtual Object* get_DataSource();
public: __property virtual void set_DataSource( 
   Object* value
);
C++/CLI 
[CategoryAttribute("Data")]
[DefaultValueAttribute()]
[BindableAttribute(Bindable=true, Direction=BindingDirection.OneWay)]
[DescriptionAttribute("Gets or sets the datasource of the grid")]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
public:
virtual property Object^ DataSource {
   Object^ get();
   void set (    Object^ value);
}

Example

 

The following sample codes show you how to do BindingHierarchical programmatically (using old databinding mode) which involves Customer, Order, and Order Details Tables :
C#Copy Code
private void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
   {
       DataSet ds = new DataSet();
       oleDbDataAdapter1.Fill(ds);
       oleDbDataAdapter2.Fill(ds);
       oleDbDataAdapter3.Fill(ds);
       ds.Relations.Add("drelation1",ds.Tables["Customers"].Columns["CustomerID"],ds.Tables ["Orders"].Columns["CustomerID"]);
       ds.Relations.Add("drelation2",ds.Tables["Orders"].Columns["OrderID"],ds.Tables["Order Details"].Columns["OrderID"]);

       e.DataSource = ds;
   }

Remarks

WebGrid accepts most of DataSource type introduced in Microsoft .NET such as DataView, DataTable or DataSet objects. You can also assign SqlDataReader, OleDbDataReader and any objects that implements IList interface. You can even use XML data or custom data class as DataSource.

One of WebGrid's key design is its ability to assign most of .NET data objects as DataSource while keeping all features to work perfectly. Unlike other controls, WebGrid's key feature such as automatic grouping, sorting, filtering and "LoadOnDemand" architecture will still work perfectly and automatically when you assign non-DataSet-based object.

WebGrid's advanced data caching mechanism will also work when you assigned non-DataSet-based objects. This enables the consistency and application of all WebGrid's key features in all DataSource type.

However, although WebGrid supports most of .NET data objects, it is always the best practice to use DataSet-based object as DataSet architecture provides many advanced functionalities such as data relations which is the key design of WebGrid's Hierarchical implementation.

In WebGrid.NET Enterprise 5.0, there are two major categories of datasource control support:

  1. Basic DataSourceControl support
    The basic datasource controls supported are: AccessDataSource, SqlDataSource, ObjectDataSource. Three of the datasource controls above support single table view and thus can only be used as flat configuration in WebGrid control.
  2. Advanced DataSourceControl support
    In addition to basic datasource controls, WebGrid.NET Enterprise 5.0 is designed to handle more advanced datasource controls for enterprise development needs. The advanced datasource controls supported are: XmlDataSource and IntersoftDataSource.

For more information, you can read the Basic DataSourceControl support and Advanced Control support

WebGrid.NET Enterprise 5.0 allows you to perform codeless data binding through DataSourceControl support. You can configure the datasource, its connection and its related property without writing codes.
Declaratively, you can create a WebCombo instance and bind it to a table in your Sql database in two simple statements as in the following:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<$ ConnectionStrings>" SelectCommand="SELECT * FROM [Tasks]"></asp:SqlDataSource>

 

<ISWebGrid:WebGrid ID="WebGrid1" runat="server" DataSourceID="SqlDataSource1" Height="300px” HorizontalAlign="NotSet" Width="100%">

</ISWebGrid:WebGrid>

From the statements above we can see the WebCombo1 is bound to a datasource control through DataSourceID property. The WebCombo connects to the specified datasource control and display data from the datasource available in SqlDataSource1.

WebGrid.NET Enterprise 5.0 still support older databinding mechanism through InitializeDataSource or DataSource property set in code behind.

  • The benefits of the new datasource control binding support: 
    Improved developers' productivity through codeless, simple and hassle-free databinding. 
  • Cleaner separation between User Interface and Data Access/Business Layer codes. All data layer codes and logics are now handled at datasource control level instead of component level. That means UI component such as WebGrid is now purely serving as data selector and combobox function, and no longer handling datasource. 
  • Better architecture. For more than decades, developer is struggling to find the best pattern in developing databound application. Datasource control binding concept is one of the most appealing and acceptable mechanism recognizing its cleaner separation between user interface and data access layer. 
  • Highly reusable. Datasource control offers better reusability since it has rock solid architecture. For instance, developer can write business layer codes in application level which is used throughout the application and use ObjectDataSource to connect to the business layer function.
  • Extensible. Datasource control such as ObjectDataSource and ISDataSource (Intersoft’s proprietary multi-views datasource control) has ability to connect to custom business layer codes. You can also connect the controls to DataSet and TableAdapter that generated using Visual Designer in Visual Studio 2005, as well as connect it to extended function that you write in an extended class through new “partial class” mechanism.

Some important things that developers need to pay attention regarding the new datasource control concept:

  • InitializeDataSource event is no longer fired when the WebCombo is bound to DataSourceID. This event will still be fired normally when the DataSourceID property is empty (old databinding mode).
  • You can not bind to datasource control and datasource object at the same time. For instance, if you set DataSourceID to SqlDataSource1 and at the same time set WebCombo1.DataSource = dsNorthWind.Customers in the code, this will throw an invalid operation exception.
  • Flat-view datasource controls that come with ASP.NET 2.0 are all supported. This includes SqlDataSource, AccessDataSource and ObjectDataSource.
  • All internal operations and existing functions in WebGrid.NET Enterprise are still working properly with the new datasource control binding such as column sorting, filtering, grouping, etc. This ensures full compatibility in behaviors and functions with the previous versions.
  • When the datasource control is configured for updating capabilities such as add new record, update record and delete record – WebGrid can automatically communicate to the assigned datasource control for its data manipulation process without any codes at the Grid level. In previous versions, developers are required to write their own codes to process the updates to physical database. For more information, refer to Walkthrough: Configuring updatable WebGrid bound to ObjectDataSource control and Walkthrough: Configuring updatable WebGrid bound to ISDataSource control
  • Data caching. In pre-2007 platform, Intersoft’s databound control such as WebCombo.NET and WebGrid.NET Enterprise employs built-in automatic data caching mechanism. In 2007 product lines, the built-in data caching is no longer functioning when the control is bound to datasource control. To configure data caching, please refer to the capability of the datasource control that you used to bound to the control. For instance, if you bind a WebGrid control to SqlDataSource, then you can enable the caching by setting EnableCaching of the SqlDataSource control to True.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

Reference

WebGrid Class
WebGrid Members

Tasks

Walkthrough: Binding WebGrid to Hierarchical ISDataSource control
Walkthrough: Binding WebGrid to ObjectDataSource control
Walkthrough: Binding WebGrid to XMLDataSource control
Walkthrough: Binding WebGrid to AccessDataSource control

Concepts

No-codes data binding through DataSourceControl support
Design-time support for DataSourceControl
Basic DataSourceControl support
Advanced DataSourceControl support

Other Resources

The benefits of the new DataSource control binding support

©2012 Intersoft Solutions Corp. All Rights Reserved.