我有3个复选框,我想根据选中的复选框填写数据库查询。到目前为止,我只能根据其中一个文本框进行搜索,但我希望能够添加无限量的类别进行搜索。
以下是我的3个复选框:
<input type="checkbox" id="CorrectionConsultantYN" value="60" />
<input type="checkbox" id="ProcessingAnalyzYN" value="10" />
<input type="checkbox" id="ProcessingConsultantYN" value="0" />
这是我的文本框:
<asp:TextBox ID="SearchValue" ClientIDMode="Static" runat="server" class="form-control form-control-pireus"></asp:TextBox>
到目前为止我的功能:
$("[type=checkbox]").change(function () {
if ($(this).is(':checked')) {
$("#SearchValue").val($(this).val());
}
else {
$("#SearchValue").val();
}
});
我希望最终结果是select * from
类似textbox
1值,textbox
2值等等。
我在这里使用Sql Server是后面的代码,只搜索1个复选框。
if (RequestFilter.SelectedValue == "krStatus")
{
query += " and d.krStatus";
}
if (FilterOp.SelectedValue == "equals")
{
query += "='" + SearchValue.Text + "'";
}
else if (FilterOp.SelectedValue == "contains")
{
query += " like '%" + SearchValue.Text + "%'";
}
else if (FilterOp.SelectedValue == "begins")
{
query += " like '" + SearchValue.Text + "%'";
}
else if (FilterOp.SelectedValue == "ends")
{
query += " like '%" + SearchValue.Text + "'";
}
以下是整个查询在结尾处的显示方式:
SELECT ROW_NUMBER() OVER(ORDER BY d.[Id]) AS RowNum,
d.Id as ROWID, d.*, CAST(e.XmlLos AS varchar(max)) AS XMLD , CASE WHEN b.Category = 2 THEN 'Ипотечен' WHEN b.Category = 3 THEN 'Овърдрафт' WHEN b.Category = 4 THEN 'Кредитна карта' ELSE 'Потребителски' END AS Category, LTRIM(RTRIM(b.Name)) AS ProdName, LTRIM(RTRIM(f.Name)) AS StatusName, LTRIM(RTRIM(g.Ccy)) AS CcyName, (CASE WHEN LTRIM(RTRIM(d.BankTragerId)) = '*' THEN '0000' ELSE LTRIM(RTRIM(d.BankTragerId)) END +'-'+ CASE WHEN LTRIM(RTRIM(d.KrDepartament)) = '*' THEN '0000' ELSE LTRIM(RTRIM(d.KrDepartament)) END +'-'+ CASE WHEN LTRIM(RTRIM(d.ProductExId)) = '*' THEN '0000' ELSE LTRIM(RTRIM(d.ProductExId)) END +'-'+ CASE WHEN (d.Id > 9999999) THEN CAST(d.Id as NVARCHAR(max)) ELSE RIGHT('0000000'+CAST(d.Id AS NVARCHAR(7)),7) END ) AS ApplicationId, ISNULL((SELECT y.DisplayName from bsUsers y WHERE y.UserID=d.UserId),' ') AS USERIDNAME, KrQueueUp, UserProcess, ISNULL((SELECT y.DisplayName from bsUsers y WHERE y.UserID=d.UserProcess),' ') AS USERPROCESSNAME
FROM [dbo].[Krdocs_Details] d, [dbo].[Products] b, [dbo].[Krdocs] e, [dbo].[Statuses] f, [dbo].[Currency] g WHERE d.Id=e.Id AND f.Code=d.KrStatus AND d.Product=b.Id AND d.CcyId = g.Id and d.KrStatus like 60