我是这里的新手,也是APS和VB的初学者,我确实有SQL经验。我遇到的问题是我试图在VBaspx页面中选择两个值。一个是可以键入的文本框,另一个是从下拉列表中选择的值,下拉列表在我的SQL数据库中看起来像一个表。我希望输入和选择后的两个值都作为新行输入到同一数据库的另一个表中,但我收到了以下错误。它把我逼得团团转。必须在ControlParameter"Product_Name"中指定ControlID
我的代码如下,我怀疑我缺少的是一些简单的东西,但我找不到它,有人能帮忙吗?
<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" />
<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> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style2"></td>
<td class="auto-style2"></td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style1"></td>
<td class="auto-style1"></td>
</tr>
</table>
<br />
<br />
<br />
感谢Kevin
您需要指定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>