DataGrid按鈕刪除確認視窗

摘要:DataGrid按鈕刪除確認視窗


//1. 於ItemDataBound事件內

protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.SelectedItem))
        {
            try
            {
                Button mybtn = (Button)e.Item.FindControl("btnDel");
                mybtn.Attributes.Add("onclick", "javascript:return confirm('確定要刪除 員工:" + e.Item.Cells[5].Text.Trim().Replace(" ", "") + " 之紀錄?');");
            }
            catch { }
        }
    }



//2.

int i;
for (i = 0; i < DataGrid1.Items.Count; i++)
{

	Button mybtn = (Button)DataGrid1.Items[i].Cells[13].Controls[1];
	mybtn.Attributes.Add("onclick", "javascript:return confirm('確定要刪除 員工:" + DataGrid1.Items[i].Cells[5].Text.Trim().Replace(" ", "") + " 之紀錄?');");
}