1

好人我提前为我的基本英语道歉。我的问题如下我在手风琴内放置了一个gridview,在另一个手风琴内。每个人都关联到一个对象数据源。现在,每个对象数据源都有一个用于编写 e.InputParameters 的 onselecting 事件。问题是我要编写的参数之一是在包含对象数据源的项目的数据项中。

obselected函数的args是:ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs

第一个是没有命名容器的 ObjectDataSourceView。而且我无法从 ObjectDataSourceSelectingEventArgs 中获得对 de dataitem 的任何引用。

所以,我的问题是如何将对象数据源的引用、包含它的项目或与该特定项目相关联的数据项获取到我的“onselecting”函数中。

提前致谢。

VB是

Imports System.Data.SqlClient

Public Class WebForm2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Page_lala(ByVal sender As Object, ByVal e As EventArgs) Handles Me.InitComplete
        Accordion1.DataSourceID = ObjectDataSource1.UniqueID
        Accordion1.DataBind()
    End Sub

    Protected Sub Accordion1_OnItemCommand(ByVal sender As Object, ByVal e As AjaxControlToolkit.AccordionCommandEventArgs) Handles Accordion1.ItemCommand
        Dim Accordion2 As Control = e.Container.FindControl("Accordion2")
        Dim objectDataSource As Control = e.Container.FindControl("ObjectDataSource2")
        If Accordion1 IsNot Nothing And objectDataSource IsNot Nothing Then
            AddHandler DirectCast(objectDataSource, ObjectDataSource).Selecting, AddressOf ObjectDataSource2_selecting
            AddHandler DirectCast(Accordion2, AjaxControlToolkit.Accordion).ItemCommand, AddressOf Accordion2_ItemCommand
            DirectCast(Accordion2, AjaxControlToolkit.Accordion).DataSourceID = DirectCast(objectDataSource, ObjectDataSource).ID
            DirectCast(Accordion2, AjaxControlToolkit.Accordion).DataBind()
        End If
    End Sub

    Protected Sub ObjectDataSource2_selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs)
        Dim parameters(0) As SqlParameter
        Dim dsv As ObjectDataSourceView = DirectCast(sender, ObjectDataSourceView)
        parameters(0) = New SqlParameter("@cliente", "30697269610")
        e.InputParameters("param") = parameters
    End Sub

    Protected Sub ObjectDataSource3_selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs)
        Dim parameters(0) As SqlParameter
        Dim dsv As ObjectDataSourceView = DirectCast(sender, ObjectDataSourceView)
        parameters(0) = New SqlParameter("@documento", "FC0030-00040199")
        e.InputParameters("param") = parameters
    End Sub

    Protected Sub Accordion2_ItemCommand(ByVal sender As Object, ByVal e As AjaxControlToolkit.AccordionCommandEventArgs) 'Handles Accordion2.ItemCommand
        Dim gridview As Control = e.Container.FindControl("gridviewAplicaciones")
        Dim objectDataSource As Control = e.Container.FindControl("ObjectDataSource3")
        If gridview IsNot Nothing And objectDataSource IsNot Nothing Then
            AddHandler DirectCast(objectDataSource, ObjectDataSource).Selecting, AddressOf ObjectDataSource3_selecting
            DirectCast(gridview, GridView).DataSourceID = DirectCast(objectDataSource, ObjectDataSource).ID
            DirectCast(gridview, GridView).DataBind()
        End If
    End Sub

End Class

asp是

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication4.WebForm2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:ScriptManager ID="ScriptManager1" runat="server" >
        </asp:ScriptManager>
            <asp:Accordion id="Accordion1" runat="server" 
             SelectedIndex="-1" RequireOpenedPane="false"  ClientIDMode="Static">
            <HeaderTemplate><%# Container.DataItem("CUSTNMBR")%> / <%# Container.DataItem("CUSTNAME")%></HeaderTemplate>
            <ContentTemplate>
                <asp:LinkButton runat="server" ID="LinkButton1" Text="ver mas 1"></asp:LinkButton>
                <asp:Accordion id="Accordion2" runat="server" OnItemCommand="Accordion2_ItemCommand"
                 SelectedIndex="-1" RequireOpenedPane="false">
                    <HeaderTemplate><%# Container.DataItem("DOCNUMBR")%></HeaderTemplate>
                    <ContentTemplate>
                    <asp:LinkButton runat="server" ID="LinkButton2" Text="Ver mas2" 
                    ></asp:LinkButton>
                    <asp:GridView runat="server" ID="gridviewAplicaciones" AutoGenerateColumns="true">
                    </asp:GridView>
                    <asp:ObjectDataSource ID="ObjectDataSource3" runat="server"
                        SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="multiconex_aplicaciones" Name="nombreSP" 
                                Type="String"  />
                            <asp:Parameter Name="param" Type="Object" />
                        </SelectParameters>
                        </asp:ObjectDataSource>
                    </ContentTemplate>

                </asp:Accordion>
                <asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
                     SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper" >
                        <SelectParameters>
                            <asp:Parameter DefaultValue="multiconex_aging" Name="nombreSP" 
                                Type="String" />
                            <asp:Parameter Name="param" Type="Object"  />
                        </SelectParameters>
                     </asp:ObjectDataSource>
                </ContentTemplate>

            </asp:Accordion>
           <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper">
                <SelectParameters>
                    <asp:Parameter DefaultValue="multiconex_rm00101" Name="nombreSP" 
                        Type="String" />
                    <asp:Parameter Name="param" Type="Object" />
                </SelectParameters>
           </asp:ObjectDataSource>
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
4

1 回答 1

0

经过大量尝试后,我没有得到对数据对象的引用,所以我在过滤器表达式中传递了数据项,并在 onselecting 函数结束时将其设为空白。

VB是

Imports System.Data.SqlClient

Public Class WebForm2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Page_lala(ByVal sender As Object, ByVal e As EventArgs) Handles Me.InitComplete
        Accordion1.DataSourceID = ObjectDataSource1.UniqueID
        Accordion1.DataBind()
    End Sub

    Protected Sub Accordion1_OnItemCommand(ByVal sender As Object, ByVal e As AjaxControlToolkit.AccordionCommandEventArgs) Handles Accordion1.ItemCommand
        Dim Accordion2 As Control = e.Container.FindControl("Accordion2")
        Dim objectDataSource As Control = e.Container.FindControl("ObjectDataSource2")
        If Accordion1 IsNot Nothing And objectDataSource IsNot Nothing Then
            AddHandler DirectCast(objectDataSource, ObjectDataSource).Selecting, AddressOf ObjectDataSource2_selecting
            AddHandler DirectCast(Accordion2, AjaxControlToolkit.Accordion).ItemCommand, AddressOf Accordion2_ItemCommand
            DirectCast(Accordion2, AjaxControlToolkit.Accordion).DataSourceID = DirectCast(objectDataSource, ObjectDataSource).ID
            'DirectCast(Accordion2, AjaxControlToolkit.Accordion).DataBind()
        End If
    End Sub

    Protected Sub ObjectDataSource2_selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs)
        Dim parameters(0) As SqlParameter
        Dim dsv As ObjectDataSourceView = DirectCast(sender, ObjectDataSourceView)
        parameters(0) = New SqlParameter("@cliente", Trim(dsv.FilterExpression))
        e.InputParameters("param") = parameters
        dsv.FilterExpression = ""
    End Sub

    Protected Sub ObjectDataSource3_selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs)
        Dim parameters(0) As SqlParameter
        Dim dsv As ObjectDataSourceView = DirectCast(sender, ObjectDataSourceView)
        parameters(0) = New SqlParameter("@documento", Trim(dsv.FilterExpression))
        e.InputParameters("param") = parameters
        dsv.FilterExpression = ""
    End Sub

    Protected Sub Accordion2_ItemCommand(ByVal sender As Object, ByVal e As AjaxControlToolkit.AccordionCommandEventArgs) 'Handles Accordion2.ItemCommand
        Dim gridview As Control = e.Container.FindControl("gridviewAplicaciones")
        Dim objectDataSource As Control = e.Container.FindControl("ObjectDataSource3")
        If gridview IsNot Nothing And objectDataSource IsNot Nothing Then
            AddHandler DirectCast(objectDataSource, ObjectDataSource).Selecting, AddressOf ObjectDataSource3_selecting
            DirectCast(gridview, GridView).DataSourceID = DirectCast(objectDataSource, ObjectDataSource).ID
            'DirectCast(gridview, GridView).DataBind()
        End If
    End Sub

End Class

而aspx是

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication4.WebForm2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" >
        </asp:ScriptManager>
            <asp:Accordion id="Accordion1" runat="server" 
             SelectedIndex="-1" RequireOpenedPane="false"  ClientIDMode="Static">
            <HeaderTemplate><%# Container.DataItem("CUSTNMBR")%> / <%# Container.DataItem("CUSTNAME")%></HeaderTemplate>
            <ContentTemplate>
                <asp:LinkButton runat="server" ID="LinkButton1" Text="ver mas 1"></asp:LinkButton>
                <asp:Accordion id="Accordion2" runat="server" OnItemCommand="Accordion2_ItemCommand"
                 SelectedIndex="-1" RequireOpenedPane="false">
                    <HeaderTemplate><%# Container.DataItem("DOCNUMBR")%></HeaderTemplate>
                    <ContentTemplate>
                    <asp:LinkButton runat="server" ID="LinkButton2" Text="Ver mas2" 
                    ></asp:LinkButton>
                    <asp:GridView runat="server" ID="gridviewAplicaciones" AutoGenerateColumns="true">
                    </asp:GridView>
                    <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" FilterExpression='<%# Container.DataItem("DOCNUMBR") %>'
                        SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper"  >
                        <SelectParameters>
                            <asp:Parameter DefaultValue="multiconex_aplicaciones" Name="nombreSP" 
                                Type="String"  />
                            <asp:Parameter Name="param" Type="Object" />
                        </SelectParameters>
                        </asp:ObjectDataSource>
                    </ContentTemplate>

                </asp:Accordion>
                <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" FilterExpression='<%# Container.DataItem("CUSTNMBR") %>'
                     SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper" >
                        <SelectParameters>
                            <asp:Parameter DefaultValue="multiconex_aging" Name="nombreSP" 
                                Type="String" />
                            <asp:Parameter Name="param" Type="Object"  />
                        </SelectParameters>
                     </asp:ObjectDataSource>
                </ContentTemplate>
            </asp:Accordion>
           <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                SelectMethod="ExecuteDataset" TypeName="WebApplication4.DbHelper">
                <SelectParameters>
                    <asp:Parameter DefaultValue="multiconex_rm00101" Name="nombreSP" 
                        Type="String" />
                    <asp:Parameter Name="param" Type="Object" />
                </SelectParameters>
           </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>
于 2012-11-06T17:02:25.300 回答