出现复选框结果后,如何减少复选框列表类别?

我有一个正在使用的网站的复选框列表类别。当在该列表中选中一个复选框时,我希望减少列表,并显示我选中的结果。我该怎么办?

Home.aspx

<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2"
    DataTextField="SBrand" DataValueField="SBrand" AutoPostBack="True"
    SelectedIndexChanged="gvStock_SelectedIndexChanged" 
    OnSelectedIndexChanged="CheckBoxList_SelectedIndexChanged" 
    OnPageIndexChanging="gvStock_PageIndexChanging" CssClass="checkboxlist">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" 
    SelectCommand="SELECT DISTINCT [SBrand] FROM [Stock]">
</asp:SqlDataSource>

Home.aspx.cs

protected void CheckBoxList_SelectedIndexChanged(object sender,EventArgs e)
{
    string chkbox = "";
    Label1.Visible = false;
    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
        if (CheckBoxList1.Items[i].Selected == true)
        {
            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],[fCost] 
                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();

        }
    }

zhao_xunze 回答:出现复选框结果后,如何减少复选框列表类别?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3155519.html

大家都在问