“/”应用程序中的服务器错误。必须在 ControlParameter 'Product_Name' 中指定 ControlID

Server Error in '/' Application. A ControlID must be specified in ControlParameter 'Product_Name'

我是新来的,是 APS 和 VB 的初学者,我确实有 SQL 经验。我遇到的问题是我试图在 VB aspx 页面中 select 两个值。 一个是可以键入的文本框,另一个是从下拉列表中 select 编辑的值,在我的 SQL 数据库中看起来像 table。 我希望这两个值一旦输入并 selected 作为新行输入到同一数据库的另一个 table 中,但我收到以下错误。它让我原地打转。 ControlParameter 中必须指定一个 ControlID 'Product_Name'。

我的代码如下,我怀疑我遗漏了一些简单的东西,但我看不到它,有人能帮忙吗?

<table style="width:100%;">
    <tr>
        <td>



            <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert">
                <InsertItemTemplate>
                    Product_Name:
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Product_Name" DataValueField="Product_Name">
                    </asp:DropDownList>
                    <ItemTemplate>
                    Product_Description:
                    <asp:TextBox ID="Product_DescriptionTextBox" runat="server" Text='<%# Bind("Product_Description") %>' />
                    <br />
                    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                    &nbsp;<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </InsertItemTemplate>
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" InsertCommand="INSERT INTO [Incidents] ( [I_Product_Name], [I_Product_Description]) VALUES ( @Product_Name, @Product_Description)">
                <InsertParameters>
                <asp:ControlParameter Name="Product_Name" Type="String" />
                    <asp:Parameter Name="Product_Description" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" SelectCommand="select Product_Name from dbo.products"></asp:SqlDataSource>

        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style2">&nbsp;</td>
        <td class="auto-style2"></td>
        <td class="auto-style2"></td>
    </tr>
    <tr>
        <td class="auto-style1">&nbsp;</td>
        <td class="auto-style1"></td>
        <td class="auto-style1"></td>
    </tr>
</table>
<br />
<br />
<br />

谢谢凯文

您需要像这样指定 ControlID & PropertyName:-

<InsertParameters>
     <asp:ControlParameter Name="Product_Name" ControlID="DropDownList1"
            PropertyName="SelectedValue" />
</InsertParameters>

编辑:- 好的,既然你用的是FormView,你需要这样指定:-

 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
      DataSourceID="SqlDataSource2" DataTextField="Product_Name"
      DataValueField="Product_Name" SelectedValue=<%# Bind('Product_Name') %>>
 </asp:DropDownList>

然后,将 InsertParameters 绑定为:-

<InsertParameters>
     <asp:Parameter Name="Product_Name" Type="String" />
     <asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>