ObjectDataSource有时找不到控制参数

本文关键字:控制 参数 找不到 ObjectDataSource | 更新日期: 2023-09-27 18:29:05

我有一个用ObjectDataSource填充的表单视图,它工作得很好。嵌套在其中的是一个网格视图,它也填充了嵌套的ODS,99%的时间都能完美工作。同样嵌套在formview中的还有另一个ODS,该ODS由填充其他嵌套数据源的同一控件填充,该控件始终完美工作。下面的代码使其有意义。

问题是,如果你更改页面,大多数情况下一切都很好。页面中内置了2个搜索功能。这就是错误发生的地方。如果你在不更改页面的情况下使用它们中的任何一个,效果都很好。如果您使用其中一个,然后更改页面并尝试使用其中任何一个,则页面将崩溃,并显示一个错误,表明在"Y"中找不到类似控制参数"X"的内容。问题是,这不是一个真正的错误,因为有一个按钮可以显示引导模型,它可以毫无问题地显示其网格视图,而ODS基于完全相同的控制,所以它显然存在。我想这与事件有关,但它们进展得很好。我不确定是什么原因造成的。

这里有一个基本上相同的小测试项目,只在formview中设置了分页,在实际项目中设置了ODS1,它运行得很好。

<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1">
    <ItemTemplate>
        ImportantID:
        <asp:Label Text='<%# Bind("ImportantID") %>' runat="server" ID="ImportantIDLabel" Visible="false" /><br />
        Name:
        <asp:Label Text='<%# Bind("Name") %>' runat="server" ID="NameLabel" /><br />
        <div id="nestedContent">
            <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="listNested" TypeName="TestProject.DataSourceClass">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ImportantIDLabel" PropertyName="Text" DefaultValue="-1" Name="ImportantIDFromOnject1ForNestedObject" Type="Int32"></asp:ControlParameter>
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource2" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="YetAnotherProperty" HeaderText="YetAnotherProperty" SortExpression="YetAnotherProperty"></asp:BoundField>
                    <asp:BoundField DataField="OtherPropertiesGoInThisClass" HeaderText="OtherPropertiesGoInThisClass" SortExpression="OtherPropertiesGoInThisClass"></asp:BoundField>
                </Columns>
            </asp:GridView>
        </div>
        SomeProperty:
        <asp:Label Text='<%# Bind("SomeProperty") %>' runat="server" ID="SomePropertyLabel" /><br />
        SomeOtherProperty:
        <asp:Label Text='<%# Bind("SomeOtherProperty") %>' runat="server" ID="SomeOtherPropertyLabel" /><br />
        <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetDataObject2" TypeName="TestProject.DataSourceClass">
            <SelectParameters>
                <asp:ControlParameter ControlID="ImportantIDLabel" PropertyName="Text" DefaultValue="-1" Name="ImportantID" Type="Int32"></asp:ControlParameter>
            </SelectParameters>
        </asp:ObjectDataSource>
        <div id="BootStrapModalPopup">
            This displays the data with no problems
        </div>
    </ItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetDataObject1" TypeName="TestProject.DataSourceClass">
    <SelectParameters>
        <asp:Parameter DefaultValue="-1" Name="ImportantID" Type="Int32"></asp:Parameter>
        <asp:Parameter DefaultValue="" Name="Name" Type="String"></asp:Parameter>
        <asp:Parameter Name="SomeProperty" Type="String"></asp:Parameter>
    </SelectParameters>
</asp:ObjectDataSource>

如果有下一步该去哪里的想法,我将不胜感激。顺便说一句,我在ID字段中使用了一个文本框、hiddencontrol和Session变量,但没有什么不同。如果我禁用ODS2,它也会恢复正常工作,但我需要这些数据。

感谢

Jimmy

ObjectDataSource有时找不到控制参数

我真的很幸运地找到了答案。这不是我的窝,而是我的寻呼。我会把这个问题留给任何有类似问题的人,因为我没有看到任何成功的错误。我面临的问题是我需要在搜索时重置页面索引。从第一页搜索效果很好,但由于索引的原因,从任何其他页面搜索都是空返回,因此控件不存在。如果你遇到这个问题,希望它能帮助人们搜索。只需将表单视图上的页面索引设置回0即可。