当条件符合复选框列表时,如何取消选中所选复选框?

时间:2014-09-30 10:22:35

标签: asp.net

我想在条件满足时取消选中所选复选框。我可以使用Checkboxlist1.ClearSelection()取消选中所有复选框。 method.But要求取消选中条件满足时选中的复选框。感谢任何帮助。

public int count;
public static int i =0;
protected void Page_Load(object sender, EventArgs e)
{ 

}
protected void chkboxlist1_click(object sender, EventArgs e)
{
    try
    {
        int conver = Convert.ToInt32(Session["ddlseats"].ToString());
        if (i >= conver)
        {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('Not More than'" + Session["ddlseats"] + "' seat(s) can be selected');", true);
                chkboxlist1.ClearSelection(chkboxlist1.Items[i].Selected);//error
        }
        else
        {
            if (chkboxlist1.SelectedItem.Selected == true && chkboxlist1.SelectedItem != null)
            {
                i = i + 1;
            }
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.ToString());
    }
}

1 个答案:

答案 0 :(得分:0)

Clearselection不接受任何输入参数。你可以直接调用它。 像这样chkboxlist1.ClearSelection();

要取消选中,单个(迭代循环),请使用以下内容。 chkboxlist1.Items[i].Selected = false;