未找到控制参数
错误:在 ControlParameter“mycontrolparam”中找不到控件“mytextfield”。
<asp:ControlParameter ControlID="mytextfield" Name="mycontrolparam" PropertyName="Text" Type="Int32" />
该错误是因为“mytextfield”位于面板控件内,我需要 FindControl 方法来查找它。但我想找到一个快速解决方案(如果有的话),如何使 mytextfield 对控制参数可见。相同的代码可以在不同的页面上运行,但不能在这个页面上运行。请记住,我想对现有代码进行最少的更改。
这是我从 Microsoft 网站复制的类似代码。
<asp:SqlDataSource id="Employees" runat="server"
ConnectionString="<%$ ConnectionStrings:Northwind%>"
SelectCommand="SELECT LastName FROM Employees WHERE Title = @Title">
<SelectParameters>
<asp:ControlParameter Name="Title"
ControlID="DropDownList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:sqldatasource>
需要提及的是:“mytextfield”是一个只读文本字段。不过在另一页上它确实工作正常。
Error: Could not find control 'mytextfield' in ControlParameter 'mycontrolparam'.
<asp:ControlParameter ControlID="mytextfield" Name="mycontrolparam" PropertyName="Text" Type="Int32" />
The error is because "mytextfield" is inside a panel control and I would need FindControl method to find it. But I want to find a quick solution if there is any, how to make mytextfield visible to the control parameter. The same code works on a different page but not on this one. Please keep in mind, I want to make minimum changes to the existing code.
Here is similar code I copied over from Microsoft site.
<asp:SqlDataSource id="Employees" runat="server"
ConnectionString="<%$ ConnectionStrings:Northwind%>"
SelectCommand="SELECT LastName FROM Employees WHERE Title = @Title">
<SelectParameters>
<asp:ControlParameter Name="Title"
ControlID="DropDownList1"
PropertyName="SelectedValue"/>
</SelectParameters>
</asp:sqldatasource>
Want to mention: 'mytextfield' is a readonly textfield. It does work OK on the other page though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选择 sqldatasource 时,请在代码隐藏页面中添加控制参数。您必须先强制转换控制,然后添加参数值。我假定名为 mypanel 的面板内有文本框 xyz 控件。
Please add control parameter inside your codebehind page when sqldatasource is selecting. You will have to cast control first and then add parameters value. I assumed textbox xyz control inside panel named mypanel.
我自己:如果一个控件嵌入在面板中,则只能通过该面板的 FindControl 方法找到它。它实际上对我来说仍然不起作用,我不得不放弃它并使用不同的方法。
否则使用以下方法
Myself: If a control is embedded inside a panel, you can only find it through FindControl method of that panel. It still actually did not work for me and I had to abandon it and use a a different method.
Use the following method otherwise