我有一个Web应用程序,我需要找到列表视图中的复选框,以检查是否已选中它以删除所选数据。我有删除按钮这样做。但是,当我按下按钮时,它没有进入listview代码,也找不到复选框。这是我的示例代码:
protected void btnDelete_Click(object sender, EventArgs e)
{
try
{
foreach (ListViewDataItem Ldi in ListView1.Items)
{
if (Ldi.ItemType == ListViewItemType.DataItem)
{
CheckBox cb = (CheckBox)(Ldi.FindControl("chkBxSelect"));
HiddenField hdnFldCandidateID = (HiddenField)(Ldi.FindControl("hdnFldCandidateID"));
string candidateID = hdnFldCandidateID.Value;
if (cb.Checked)
{
con.Open();
query = "delete from candidates where candidate_id=" + candidateID + "";
cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("candidate-search");
}
else
{
ShowAlert("Please select one cadidate to Delete");
}
}
}
}
catch (Exception ex)
{
Response.Write("Error:" + ex);
}
finally
{
con.Close();
}
}