如何选中复选框后立即显示结果

问题描述 投票:0回答:1

我正在使用ASP.net GridView。在选中复选框并单击搜索按钮之后,有一些复选框可以过滤结果,但是我想删除按钮以在选中复选框后自动进行过滤。]

Gridview中显示的内容来自数据库表

ASP

<b><label style="font-size:25px">Brand</label></b>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="SBrand" DataValueField="SBrand">

</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT DISTINCT [SBrand] FROM [Stock]"></asp:SqlDataSource>

C#

protected void gvStock_SelectedIndexChanged(object sender, EventArgs e)
        {
            string id = gvStock.SelectedRow.Cells[0].Text;
            Response.Redirect("Details.aspx?ID=" + id);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string chkbox = "";
            Label1.Visible = false;
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    if (chkbox == "")
                    {
                        chkbox = "'" + CheckBoxList1.Items[i].Text + "'";
                    }
                    else
                    {
                        chkbox += "," + "'" + CheckBoxList1.Items[i].Text + "'";
                    }
                    Label1.Text = chkbox;

                    string mainconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                    SqlConnection sqlconn = new SqlConnection(mainconn);
                    string sqlquery = "SELECT [pCode],[pID],[bCode], [SBrand], [SDescription], [sCost] , [sPrice] , [SType] , [sSupplierName] , [sSupplierDirect] FROM Stock where SBrand in (" + Label1.Text + ")";
                    SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
                    sqlconn.Open();
                    SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    this.gvStock.DataSource = dt;
                    this.gvStock.DataBind();

                }
            }
        }

我正在使用ASP.net GridView。在选中复选框并单击搜索按钮之后,有一些复选框可以过滤结果,但是我想删除该按钮以在...

asp.net search filter checkboxlist
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.