在代码隐藏中覆盖数据源的 ControlParameters
我有一个 ObjectDataSource (但也许这个问题对于所有支持参数集合的 DataSource 都是相同的):
<asp:ObjectDataSource ID="MyObjectDataSource" runat="server"
TypeName="MyData"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMyData" >
<SelectParameters>
<asp:ControlParameter ControlID="MyTextBox" Name="MyParameter" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
正如您所看到的,有一个 ControlParameter 绑定到 aspx 页面上的 TextBox。所以这个TextBox的内容是我的SelectMethod的一个参数。但是页面上有一个特殊的按钮:当单击此按钮并发生回发时,我不希望 DataSource 提取 TextBox 的内容来控制选择,而是想设置一个特定的硬值“x”作为选择参数。
我怎样才能做到这一点?单击此特定按钮时,我可以以某种方式“禁用”ControlParameter 并设置我的特殊值吗?或者还有其他办法吗?
感谢您提前的反馈!
I have an ObjectDataSource (but perhaps this question is the same for all kinds of DataSources which support parameter collections):
<asp:ObjectDataSource ID="MyObjectDataSource" runat="server"
TypeName="MyData"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMyData" >
<SelectParameters>
<asp:ControlParameter ControlID="MyTextBox" Name="MyParameter" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
As you can see there is a ControlParameter bound to a TextBox on the aspx page. So the content of this TextBox is a parameter for my SelectMethod. But there is a special button on the page: When this button is clicked and a postback occurs I don't want that the DataSource extracts the content of the TextBox to control the selection, instead I want to set a specific hard value "x" as the selection parameter.
How can I do that? Can I "disable" in some way the ControlParameter when this specific button is clicked and set my special value instead? Or is there any other way?
Thank you for feedback in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了这个解决方案:
我用“通用”参数替换了
asp:ControlParameter
:...然后在特殊按钮的事件处理程序
中: 在按钮,该按钮将通过文本框内容运行选择:
我不知道这是否是一个好的解决方案,或者它是否会产生不希望的副作用。但目前它有效。 (无论如何,我想知道“通用”参数的目的是什么。也许正是这样:仅由代码隐藏设置的“未绑定”参数(除了作为自定义参数类的基类之外))。
I've found this solution myself:
I've replaced the
asp:ControlParameter
by a "generic" parameter:...and then in the event handler for the special button:
In the event handler of the button which shall run the selection by the TextBox content:
I don't know if this is a good solution or if it can have unwished side effects. But at the moment it works. (I was wondering anyway what's the purpose of "generic" parameters. Perhaps exactly this: "Unbound" parameters to be set only by code-behind (aside from being the base class of customized parameter classes)).