嗨,gusy,我试图了解如何使用带有复选框的grindview 从数据库中删除,但我不知道为什么 deleteresults.text 和 DeleteResults.Visible 不起作用这是我的代码(我是编程新手 :) 并感谢您的回答
protected void Button3_Click(object sender, EventArgs e)
{
bool atLeastOneRowDeleted = false;
// Iterate through the Products.Rows property
foreach (GridViewRow row in Products.Rows)
{
// Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("selector");
if (cb != null && cb.Checked)
{
// Delete row! (Well, not really...)
atLeastOneRowDeleted = true;
// First, get the ProductID for the selected row
int id_offre = Convert.ToInt32(Products.DataKeys[row.RowIndex].Value);
// "Delete" the row
DeleteResults.Text += string.Format("This would have deleted ProductID {0}<br />", id_offre);
}
}
// Show the Label if at least one row was deleted...
DeleteResults.Visible = atLeastOneRowDeleted;
}