Intersoft WebGrid Documentation
OnInitializeDataSource Method
See Also  Example Send Feedback
ISNet.WebUI.WebGrid Namespace > WebGrid Class : OnInitializeDataSource Method






dataSource
A reference to the dataSource object.
Invoked when data source need to be initialized. It is highly recommended that you use this event to initialize your databinding code for more centralized and easy to maintain codes.

Syntax

Visual Basic (Declaration) 
Public Overridable Function OnInitializeDataSource( _
   ByVal dataSource As Object _
) As Boolean
Visual Basic (Usage)Copy Code
Dim instance As WebGrid
Dim dataSource As Object
Dim value As Boolean
 
value = instance.OnInitializeDataSource(dataSource)
C# 
public virtual bool OnInitializeDataSource( 
   object dataSource
)
Delphi 
public function OnInitializeDataSource( 
    dataSource: TObject
): Boolean; virtual; 
JScript 
public function OnInitializeDataSource( 
   dataSource : Object
) : boolean;
Managed Extensions for C++ 
public: virtual bool OnInitializeDataSource( 
   Object* dataSource
) 
C++/CLI 
public:
virtual bool OnInitializeDataSource( 
   Object^ dataSource
) 

Parameters

dataSource
A reference to the dataSource object.

Return Value

Returns ReturnValue. Event will be cancelled when ReturnValue is False.

Example

 

C#Copy Code
protected void WebGrid1_InitData(object sender, DataSourceEventArgs e)  
{ 
    // the codes will only be executed on first page load, when refresh function invoked 
    // from client, or when the cache is expired/cleared. 
     
    sqlDataAdapter1.Fill(dataSet11.Customers); 
    e.DataSource = dataSet11; 
}

Remarks

Instead of writing your databinding code in Page_Load event, it is more effective to use InitializeDataSource event as a central place for the Grid's databinding code. By using this event, you are automatically taking advantage of the Grid's automatic data caching feature.

Note that you don't need to use IsDataCached to query the DataCache status since that the control will automatically check it and only call this event when it needs DataSource. You also don't need to put it under !IsPostBack or other conditions because the event is only fired on first page load, on refresh, or when the cache has been cleared/expired. Additionally, the databinding code has been very simplified so that you don't have to call DataBind after you assign the DataSource as needed by other controls normally.

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

©2012 Intersoft Solutions Corp. All Rights Reserved.