views:

240

answers:

2

CheckPara is my OnDataBinding procedure

SqlDataSource1 is ObjectDataSource (it's only confusing name)

Language is Nemerle, but if you know C# you can read it easy

  protected virtual CheckPara(_ : object,  _ : System.EventArgs) : void
      {
        foreach(x is Parameter in SqlDataSource1.SelectParameters)
            when(x.DefaultValue=="") //Cancel binding
      }

so how can I cancel binding when there is not fully configurated ObjectDataSource ?

Or... how can I run binding only when I done with all parameters ?

+1  A: 

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
AMissico
it binds by default for me :-/ . . . there is no Bind methods on my Page_Load... only setup some parameters. Can't find where it binds...
nCdy
Ah, I just remembered. Did you declare the ObjectDataSource in the aspx file? If so, it data binds on...<forgot>. Will handling the ObjectCreating event help you.
AMissico
may you share some example code... ?
nCdy
Ah, I just remembered. Did you declare the ObjectDataSource in the aspx file? If so, it data binds immediately after Page.Load event and before Control.Load event. Will handling the ObjectCreating event help you.
AMissico
Visual basic :(
nCdy
+1  A: 

Use ObjectDataSource's Selecting event, place your for loop of select and if you want to cancel binding it, use e.Cacnel = true and you are done!!

lakhlaniprashant.blogspot.com