Page Life Cycle and Data Binding events of Data Bound Controls

For Data-bound controls like FormView, GridView & DetailsView following are the events in order of execution to be taken in to consideration during page life cycle. This article describes about Page Life Cycle and Data Binding events of Data Bound Controls.

DataBinding –
• Raised after PreRender event of control if control's DataSourceID property is set declaratively else happens when control's DataBind method is called.
• Binds control to the data.

ItemCreated (DataList,DataGrid,Repeater etc.) OR RowCreated (GridView) –
• Mainly used for programmatically modify content which is not dependent on data binding.

RowDataBound((Gridview) OR ItemDataBound(DataList,DataGrid,Repeater etc.) –
• Here data is available; this data can be formatted or filtered to show related data.

DataBound –
• Use this event to format data – bound content or to initiate data binding in other controls that depend on values from current control.

In case of Nested data-bound controls it is necessary to keep data in parent and child control in synch, this holds true where data in child control performs processing based on data in parent control.
For example: A gridView control displays student record in each row, and it displays subjects student has opted for in ListBox control. To show up subjects List box control would be bound to some data source that fetch data based on StudentId.
If ListBox control's data binding properties such as DataSourceId is set declaratively then it will try to bind to data source during containing row's data bind event. But, StudentId will not be available until GridView's RowDataBound event; which would result in fetched data being out of synch with parent data.
To avoid above situation, put the data source control for list box control in the same template as list box control itself and do not set the data binding properties of list box control declaratively. Set them programmatically at the run time during RowDataBind event.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: