0
我不知道如何對點擊後保存選擇的參數「搜索」實現邏輯後點擊搜索 - 選擇價值被複位,不存儲
有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>
eg 如果我檢查3的複選框 - 備件,第一罷了,專用工具 - 點擊「搜索」> 響應寫結果: ...及其附件= 1和firstfills = 1和specialtools = 1
如果後我取消第一隻填充 - 點擊 '搜索'> ...及其附件= 0和firstfills = 0和specialtools = 0
結果,我需要: ...及其附件= 1和firstfills = 0和specialtools = 1
對不起,我的錯,做 –
您必須啓用'AutoPostBack'上的複選框,否則經過方法不會火和變量將不會被設置。 –