嘿,我有一个用数据库填充的 CheckBoxList。当我对单个复选框的状态(选中或取消选中)进行任何更改时,提交表单时它不会返回。
以最简单的形式,我有:
<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();
}
}
我错过了什么吗?谢谢。