因此,我一直在使用具有多个控制参数的 sqldatasource 在 asp.net 中进行搜索。如果填写了一个控件,但另一个控件没有填写,我花了一些时间研究让我的表格可搜索(如果我将一个留空,它不会带来任何东西)。我现在唯一的问题是,一旦页面打开,它将用整个数据库填充网格视图。也许我做错了,但我的最终目的是有一个带有 8 个文本框的搜索页面来搜索数据库。任何帮助将不胜感激。不确定这是否是您需要的所有信息,但请告诉我。提前谢谢大家。
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Conn %>" CancelSelectOnNullParameter="false"
SelectCommand="SELECT [ID], [ContractNo], [OMBEmp], [Cono], [ReviewDate], [AmendNo], [RType], [Contractor], [Purpose], [Department] FROM [tblContractLog] WHERE (([ContractNo] = @ContractNo OR @ContractNo = '') AND ([OMBEmp] = @OMBEmp OR @OMBEmp = '') AND ([Cono] = @Cono OR @Cono = '') AND ([AmendNo] = @AmendNo OR @AmendNo = '') AND ([RType] = @RType OR @RType = '') AND ([Contractor] = @Contractor OR @Contractor = '') AND ([Purpose] = @Purpose OR @Purpose = '') AND ([Department] = @Department OR @Department = ''))">
<SelectParameters>
<asp:ControlParameter ControlID="contractnumb" Name="ContractNo"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="employeetext" Name="OMBEmp"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="conumb" Name="Cono"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="amendnumbtxt" Name="AmendNo"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="rtypetxt" Name="RType"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="contractortxt" Name="Contractor"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="purposetxt" Name="Purpose"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="departmenttxt" Name="Department"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="false"/>
</SelectParameters>
</asp:SqlDataSource>