I've done this in the past:
Assuming that you're setting the DataKeyField when databinding, you can
use code similar to the following on the button's click event -
private void dgDelete_OnClick(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach( DataGridItem item in dg.Items )
{
HtmlInputCheckBox chkBox =
(HtmlInputCheckBox) item.FindControl("checkboxCol");
//If it's selected then delete it
if ( chkBox != null && chkBox.Checked )
{
int objectID =(int)dg.DataKeys[(int)e.Item.ItemIndex];
//call delete code here for the given objectID
}
}
}
|