Question

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 ?

Was it helpful?

Solution

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!!

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top