ASP.NET does not bind by default. You must call DataBind
. Calling Page.DataBind
will call all control's DataBind
method. Therefore, just call your control's DataBind
when ready. I usually do not call Page.DataBind
when using an ObjectDataSource
.
If you have declared an ObjectDataSource
in your Web Form (aspx) page, then the control's DataBind
method is called immediately after the Page.Load
event and before the control's Load
event. The ObjectCreating
and ObjectCreated
events may be of help to you. Following is a sample that sets the business object's connection string.
<asp:ObjectDataSource
ID="__definitionCategoryDataSource"
runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="Missico.Data.DefinitionDataSetTableAdapters.DefinitionCategoryTableAdapter">
</asp:ObjectDataSource>
Protected Sub __definitionCategoryDataSource_ObjectCreated( _
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.ObjectDataSourceEventArgs) _
Handles __definitionCategoryDataSource.ObjectCreated
If e.ObjectInstance IsNot Nothing Then
SetObjectDataSourceConnectionString(e.ObjectInstance, DataManager.ConnectionString)
End If
End Sub
Public Sub SetObjectDataSourceConnectionString( _
ByVal objectInstance As Object, _
ByVal connectionString As String)
If objectInstance IsNot Nothing Then
Dim oConnection As System.Data.Common.DbConnection
oConnection = objectInstance.GetType.GetProperty("Connection").GetValue(objectInstance, Nothing)
oConnection.ConnectionString = DataManager.ConnectionString
End If
End Sub