CheckBoxList未更新,处于已检查/未检查状态 [英] CheckBoxList not updating it's checked/not checked state

查看:81
本文介绍了CheckBoxList未更新,处于已检查/未检查状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个CheckBoxList,其中填充了数据库。当我对单个复选框的状态(选中或取消选中)进行任何更改时,提交表单时都不会返回。

Hey, I have a CheckBoxList that gets populated with the database. When I make any changes to the state (check or uncheck) of a single checkbox, it doesn't get returned when I submit my form.

最简单的形式是:

<asp:CheckBoxList runat="server" ID="listEmployes" RepeatDirection="Horizontal">
</asp:CheckBoxList>

C#:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    _connection.Open();

    var employes = listEmployes.Items;

    foreach (ListItem employe in employes)
    {
        if (employe.Selected)
        {
            _command = new MySqlCommand(String.Format("INSERT IGNORE INTO Liste_Employes (Projet_ID, User_ID) VALUES ({0}, {1})", _projetId, employe.Value), _connection);
        }
        else
        {
            _command = new MySqlCommand(String.Format("DELETE IGNORE FROM Liste_Employes WHERE Projet_ID = {0} AND User_ID = {1}", _projetId, employe.Value), _connection);
        }

        _command.ExecuteNonQuery();
    }


}

我失踪了什么东西谢谢。

Am I missing something? Thanks.

推荐答案

请确保您的CheckBoxList不会在回发时反弹(如果您是从代码进行数据绑定)。

Make sure your CheckBoxList is not being rebound on postbacks (if you're databinding from code).

If(!Page.IsPostBack) 
{
    // Bind code
}

这篇关于CheckBoxList未更新,处于已检查/未检查状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆