未找到控制参数

发布于 2024-11-27 08:58:04 字数 850 浏览 4 评论 0原文

错误:在 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 技术交流群。

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

发布评论

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

评论(2

别念他 2024-12-04 08:58:04

选择 sqldatasource 时,请在代码隐藏页面中添加控制参数。您必须先强制​​转换控制,然后添加参数值。我假定名为 mypanel 的面板内有文本框 xyz 控件。

Protected Sub Employees_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Employees.Selecting
            Dim xyz As TextBox = DirectCast(mypanel.findcontrol("yourcontrolname"), TextBox)
            Dim mycontrolparam = New SqlParameter("@mycontrolparam",xyz.text)
            e.Command.Parameters.Add(mycontrolparam)
        End Sub

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.

Protected Sub Employees_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles Employees.Selecting
            Dim xyz As TextBox = DirectCast(mypanel.findcontrol("yourcontrolname"), TextBox)
            Dim mycontrolparam = New SqlParameter("@mycontrolparam",xyz.text)
            e.Command.Parameters.Add(mycontrolparam)
        End Sub
提笔书几行 2024-12-04 08:58:04

我自己:如果一个控件嵌入在面板中,则只能通过该面板的 FindControl 方法找到它。它实际上对我来说仍然不起作用,我不得不放弃它并使用不同的方法。

否则使用以下方法

FindControl("MyControlID")

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

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