asp.net - 如何将 RadioButtonList 项绑定到 ControlParameter
问题描述
如何将选定的 RadioButtonList 项绑定到我的查询的 controlParameter?
我有以下内容,但[OleDbException (0x80040e14): Missing operand.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1216113 ...
出现错误。
<asp:TextBox runat="server" id="first" ></asp:TextBox> Enter Account (Owner ID) Number with dashes if applicable. <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>
解决方案
您可以命名控件属性并使用 @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>
推荐阅读
- r - 带矩阵的文本文件
- python - 将 complex64 数据输入 Keras 顺序模型
- java - java中的AES加密和使用CryptoJS的javascript中的解密
- firebird - 如何在 SELECT 子句中显式设置常量值的类型
- android - Firebase 远程配置默认值中的条件
- python - 'WindowsPath' 类型的对象无法转换为 COM VARIANT
- libtorch - 使用 nn::sequential 访问权重和偏差
- nginx - 三个同时调用导致每个调用的进程峰值达到 25%
- android-sqlite - 向 sqlite 数据库添加列
- php - 在数据表中显示选择标签 (CodeIgniter)