如何取消绑定ObjectDataSource?

发布于 2024-08-26 04:31:22 字数 444 浏览 7 评论 0原文

CheckPara 是我的 OnDataBinding 过程

SqlDataSource1 是 ObjectDataSource (这只是令人困惑的名称)

语言是 Nemerle,但如果您了解 C#,您可以轻松阅读它,

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

那么当没有完全配置的 ObjectDataSource 时,如何取消绑定?

或者...如何仅在完成所有参数后才运行绑定?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

私藏温柔 2024-09-02 04:31:22

使用 ObjectDataSource 的 Selecting 事件,放置 select 的 for 循环,如果您想取消绑定它,请使用 e.Cacnel = true 即可完成!

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

寄居者 2024-09-02 04:31:22

ASP.NET 默认情况下不绑定。您必须调用DataBind。调用Page.DataBind将调用所有控件的DataBind方法。因此,只需在准备好后调用控件的 DataBind 即可。使用 ObjectDataSource 时,我通常不会调用 Page.DataBind

如果您在 Web 窗体 (aspx) 页中声明了 ObjectDataSource,则在 Page.Load 事件之后立即调用该控件的 DataBind 方法并且在控件的 Load 事件之前。 ObjectCreatingObjectCreated 事件可能对您有帮助。以下是设置业务对象的连接字符串的示例。


<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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文