首页 > 解决方案 > 如何将 RadioButtonList 项绑定到 ControlParameter

问题描述

如何将选定的 RadioButtonList 项绑定到我的查询的 controlParameter?

我有以下内容,但[OleDbException (0x80040e14): Missing operand.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1216113 ...出现错误。

    <asp:TextBox runat="server" id="first" ></asp:TextBox>&nbsp;Enter Account (Owner ID) Number with dashes if applicable.&nbsp;<br />     
    <asp:TextBox runat="server" id="second" ></asp:TextBox><br />
    <asp:TextBox runat="server" id="third" ></asp:TextBox><br />
    ...
    ...
    <asp:RadioButtonList id="accountType" runat="server">
        <asp:ListItem text="foo" value="foo" selected="true"/>
        <asp:ListItem text="bar" value="bar" />
    </asp:RadioButtonList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>" 
     SelectCommand="SELECT * FROM dbtable WHERE (ACCT = @first OR ACCT = @second OR ACCT = @third) AND unpaid > 0 AND type = @accountTypeSelect ORDER BY acct ASC" >
  <SelectParameters>           
     <asp:ControlParameter ControlID="first" Name="first" PropertyName="Text" Type="String" DefaultValue ="-1" />
     <asp:ControlParameter ControlID="second" Name="second" PropertyName="Text" Type="String" DefaultValue ="-1"/>
     <asp:ControlParameter ControlID="third" Name="third" PropertyName="Text" Type="String" DefaultValue ="-1" />
     <asp:ControlParameter ControlID="accountType" Name="accountTypeSelect" PropertyName="SelectedValue" type="String"/>            
   </SelectParameters>
</asp:SqlDataSource>

标签: asp.net

解决方案


您可以命名控件属性并使用 @controlname 添加到您的 sql 中,查看此链接以获取示例SqlDataSource.SelectParameters 属性

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>" ProviderName="<%$ ConnectionStrings:db.ProviderName %>" 
     SelectCommand="SELECT * FROM dbtable WHERE (ACCT = @first OR ACCT = @second OR ACCT = @thrid) AND unpaid > 0 AND type = @accountTypeSelect ORDER BY acct ASC" >
  <SelectParameters>           
     <asp:ControlParameter ControlID="first" Name="first" PropertyName="Text" Type="String" DefaultValue ="-1" />
     <asp:ControlParameter ControlID="second" Name="second" PropertyName="Text" Type="String" DefaultValue ="-1"/>
     <asp:ControlParameter ControlID="third" Name="third" PropertyName="Text" Type="String" DefaultValue ="-1" />
     <asp:ControlParameter ControlID="accountType" Name="accountTypeSelect" PropertyName="SelectedValue" type="String"/>            
   </SelectParameters>
</asp:SqlDataSource>

推荐阅读