2012-10-25 61 views
0

我有访问数据源加载列表框值。我试图传递一个参数到accessdatasource,但我不知道我做错了什么。c#将下拉列表中的选定值传递给accessdatasource selectparameter

<asp:DropDownList ID="customerName" runat="server"> 
    <asp:ListItem value="69" Text="Danny"></asp:ListItem> 
    <asp:ListItem value="23" Text="Sarah"></asp:ListItem> 
</asp:DropDownList> 

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="/App_Data/data.mdb" SelectCommand="SELECT * FROM table WHERE customerID='?'"> 

<selectparameters> 
    <asp:ControlParameter Name="customerID" ControlID="customerName" PropertyName="SelectedValue" /> 
</selectparameters> 

<asp:ListBox ID="lstCustomers" runat="server" AutoPostBack="True" 
     DataSourceID="AccessDataSource1" DataTextField="customerName" 
     DataValueField="customerID" Width="175px" Height="365px" 
      onselectedindexchanged="lstCustomers_SelectedIndexChanged"></asp:ListBox> 

该列表返回为空......不知道我在做什么错了!

+1

您是否需要围绕参数占位符的单引号?改为尝试'WHERE customerID =?'。 –

+0

这是工作!谢谢 –

回答

0

只是澄清..这是由理查德迪明解决,但没有答案回答。我会在这里发布代码

它是通过删除单引号来解决的?参数在SQL中

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="/App_Data/data.mdb" SelectCommand="SELECT * FROM table WHERE customerID=?"> 
相关问题