我不明白单击“搜索”后如何实现保存所选参数的逻辑
有aspx文件:
<form class="search_css" runat="server">
<div class="search_div_search_box">
<table class="filter_component_css">
<tr>
<td>miap</td>
<td><asp:TextBox CssClass="search_format" ID="miap_textbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>purchase order</td>
<td><asp:TextBox CssClass="search_format" ID="po_textbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>material desc</td>
<td><asp:TextBox CssClass="search_format" ID="material_desc_textbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>supplier</td>
<td><asp:TextBox CssClass="search_format" ID="supplier_textbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>manufacturer</td>
<td><asp:TextBox CssClass="search_format" ID="manufacturer_textbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>spare parts</td>
<td><asp:CheckBox CssClass="search_format" ID="parts_checkbox" runat="server" OnCheckedChanged="spareParts_Checked" ViewStateMode="Enabled"/></td>
</tr>
<tr>
<td>first fills</td>
<td><asp:CheckBox CssClass="search_format" ID="fills_checkbox" runat="server" OnCheckedChanged="firstFills_Checked" ViewStateMode="Enabled"/></td>
</tr>
<tr><td>special tools</td>
<td><asp:Checkbox CssClass="search_format" ID="tools_checkbox" runat="server" OnCheckedChanged="specialTools_Checked" ViewStateMode="Enabled"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="buttonReset" CssClass="filter_component_css_3" runat="server" Text="Reset" OnClick="submitResetClick"/>
<asp:Button ID="buttonSearch" CssClass="filter_component_css_3" runat="server" Text="Search" OnClick="submitSearchClick"/>
</td>
</tr>
</table>
</div>
</form>
c#类:
<script runat="server">
//spare parts variable
int sp_id=0;
//first fills variable
int ff_id=0;
//special tools variable
int st_id=0;
void spareParts_Checked(Object sender, EventArgs e)
{
if (parts_checkbox.Checked)
{
sp_id = 1;
}
}
void firstFills_Checked(Object sender, EventArgs e)
{
if (fills_checkbox.Checked)
{
ff_id = 1;
}
}
void specialTools_Checked(Object sender, EventArgs e)
{
if (tools_checkbox.Checked)
{
st_id = 1;
}
}
protected void submitSearchClick(object sender, EventArgs e)
{
ViewState.Add("flag", true);
ViewState.Add("sp_id", sp_id);
ViewState.Add("ff_id", ff_id);
ViewState.Add("st_id", st_id);
GridViewS.DataSource = SqlDataSource_Search;
Response.Write("miap like '%" + miap_textbox.Text + "%' and pocode like '%" + po_textbox.Text + "%' and materialdescription like '%" + material_desc_textbox.Text + "%' and suppliername like '%" + supplier_textbox.Text + "%' and manufacturername like '%" + manufacturer_textbox.Text
+ "%' and spareparts =" + sp_id + " and firstfills=" + ff_id + " and specialtools =" + st_id + "");
SqlDataSource_Search.FilterExpression = "miap like '%" + miap_textbox.Text + "%' and pocode like '%" + po_textbox.Text + "%' and materialdescription like '%" + material_desc_textbox.Text + "%' and suppliername like '%" + supplier_textbox.Text + "%' and manufacturername like '%" + manufacturer_textbox.Text
+ "%' and spareparts =" +sp_id+ " and firstfills=" +ff_id+ " and specialtools =" + st_id + "";
GridViewS.DataBind();
}
</script>
例如,如果我选中 3 个复选框 - 备件、首次填充、特殊工具 - 单击“搜索”> 响应写入结果:... 和备件 =1 和首次填充 =1 和特殊工具 =1
如果在那之后我取消选中仅第一次填充 - 单击“搜索”> ... 和备件 =0 和 firstfills=0 和 specialtools =0
我需要的结果: ... 和备件 =1 和 firstfills=0 和 specialtools =1