D
Darren
Hey folks,
I have an application that needs to delete multiple datagrid rows (Hotmail
style). I modeled mine after the article at http://aspalliance.com/427
Here is my delete button click event logic:
private void btnDelete_Click(object sender, System.EventArgs e)
{
CheckBox chk = null;
bool chkSelected = false;
foreach (DataGridItem item in dgNew.Items)
{
if (item.ItemType != ListItemType.Header && item.ItemType !=
ListItemType.Footer && item.ItemType != ListItemType.Pager)
{
chk = (CheckBox)item.Cells[0].FindControl("chkSelect");
chkSelected = chk.Checked;
if (chkSelected)
{
int appId = Convert.ToInt32(dgNew.DataKeys[item.ItemIndex].ToString());
sqlCommand1.Parameters["@AppId"].Value = appId;
sqlConnection1.Open();
sqlCommand1.ExecuteNonQuery();
sqlConnection1.Close();
}
}
}
dgNew.EditItemIndex = -1;
BindGrid();
}
The problem is that even though I have some of the checkboxes checked, when
I step into this event, it reports that all checkboxes are NOT checked. Is
there something I am missing?
Thanks,
Darren
I have an application that needs to delete multiple datagrid rows (Hotmail
style). I modeled mine after the article at http://aspalliance.com/427
Here is my delete button click event logic:
private void btnDelete_Click(object sender, System.EventArgs e)
{
CheckBox chk = null;
bool chkSelected = false;
foreach (DataGridItem item in dgNew.Items)
{
if (item.ItemType != ListItemType.Header && item.ItemType !=
ListItemType.Footer && item.ItemType != ListItemType.Pager)
{
chk = (CheckBox)item.Cells[0].FindControl("chkSelect");
chkSelected = chk.Checked;
if (chkSelected)
{
int appId = Convert.ToInt32(dgNew.DataKeys[item.ItemIndex].ToString());
sqlCommand1.Parameters["@AppId"].Value = appId;
sqlConnection1.Open();
sqlCommand1.ExecuteNonQuery();
sqlConnection1.Close();
}
}
}
dgNew.EditItemIndex = -1;
BindGrid();
}
The problem is that even though I have some of the checkboxes checked, when
I step into this event, it reports that all checkboxes are NOT checked. Is
there something I am missing?
Thanks,
Darren