0
嘿,我有一個CheckBoxList被填充到數據庫中。當我對單個複選框的狀態(選中或取消選中)進行任何更改時,在提交表單時不會返回。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();
}
}
我缺少的東西?謝謝。
感謝它的工作。來自PHP編碼器,ASP.net有我自己特殊的方式,我猜... – ademers 2009-11-21 19:09:10