Intersoft WebGrid Documentation
InitializeDataSource Event
See Also  Example Send Feedback
ISNet.WebUI.WebGrid Namespace > WebGrid Class : InitializeDataSource Event






Occurs when a datasource needs to be initialized during data binding.

Syntax

Visual Basic (Declaration) 
<DescriptionAttribute()>
<CategoryAttribute("Behavior")>
Public Event InitializeDataSource As DataSourceEventHandler
Visual Basic (Usage)Copy Code
Dim instance As WebGrid
Dim handler As DataSourceEventHandler
 
AddHandler instance.InitializeDataSource, handler
C# 
[DescriptionAttribute()]
[CategoryAttribute("Behavior")]
public event DataSourceEventHandler InitializeDataSource
Delphi 
public event InitializeDataSource: DataSourceEventHandler; 
JScript 
In JScript, you can handle the events defined by another class, but you cannot define your own.
Managed Extensions for C++ 
[DescriptionAttribute()]
[CategoryAttribute("Behavior")]
public: __event DataSourceEventHandler* InitializeDataSource
C++/CLI 
[DescriptionAttribute()]
[CategoryAttribute("Behavior")]
public:
event DataSourceEventHandler^ InitializeDataSource

Event Data

The event handler receives an argument of type DataSourceEventArgs containing data related to this event. The following DataSourceEventArgs properties provide information specific to this event.

PropertyDescription
DataSource Gets or sets the DataSource for the control.
ReturnValue (Inherited from ISNet.WebUI.WebGrid.BaseEventArgs) 

Example

The following example shows you how to bind datasource after you have generated DataSet.
C#Copy Code
private void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.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.
     
     oleDbDataAdapter1.Fill(dataSet11.Employees);
     e.DataSource = dataSet11;
}
The following example shows you how to bind datasource programmatically using DataSet in InitializeDataSource Event.
C#Copy Code
The following example shows you how to bind datasource programmatically using DataSet in InitializeDataSource Event: Notes: If you bind data source programmatically, you need to put WebGrid1.RetrieveStructure(); under if(!IsPostBack) in Prepare DataBinding Event.
C#Copy Code
private void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
     DataSet ds = new DataSet();
     oleDbDataAdapter1.Fill(ds);
     e.DataSource = ds;
}

Remarks

The InitializeDataSource event is used to provide datasource to the grid easily in one centralized environment. The event also takes advantage of the built-in automated data caching and therefore is the most recommended way to perform databinding for maximum performance gain.

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 do not 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.

WebGrid.NET Enterprise 5.0 introduces you to a new code-less data binding. Binding is supported through DataSource support. With this 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). Programming databind web application is very easy, simple and straightforward. There are no codes that required in the page’s code behind if you use datasource control.

For more information you can read Walkthrough: Binding WebGrid to AccessDataSource control, Walkthrough: Binding WebGrid to ObjectDataSource control, and Walkthrough: Binding WebGrid to XMLDataSource control.

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: Applying Late Binding Hierarchical
Walkthrough: Binding WebGrid to AccessDataSource control
Walkthrough: Binding WebGrid to ObjectDataSource control
Walkthrough: Binding WebGrid to XMLDataSource control

Concepts

No-codes data binding through DataSourceControl support

Other Resources

Retrieve Structure and Hierarchical Structure Context Command
Hierarchical DataSource control

©2012 Intersoft Solutions Corp. All Rights Reserved.