|
using System;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
namespace ooaspnet
{
/// <summary>
///
/// </summary>
public class ConfirmDelDataGrid : System.Web.UI.WebControls.DataGrid
{
// Index of the "Delete" command column for this grid
protected int delcol = -1;
protected bool confirmdel = true;
// Property to enable/disable deletion confirmation
public bool ConfirmOnDelete
{
get { return confirmdel; }
set { confirmdel = value; }
}
public ConfirmDelDataGrid()
{
}
protected override ArrayList CreateColumnSet(PagedDataSource dataSource, bool useDataSource)
{
// Let the DataGrid create the columns
ArrayList list = base.CreateColumnSet (dataSource, useDataSource);
// Examine the columns
delcol=0;
foreach (DataGridColumn col in list)
{
// If this column is the "Delete" button command column...
if ((col is ButtonColumn) && (((ButtonColumn)col).CommandName == "Delete"))
{
// Found it
break;
}
delcol++;
}
// If we did not find a delete column, invalidate the index
if (delcol == list.Count) delcol = -1;
// Done
return list;
}
protected override void OnItemDataBound(DataGridItemEventArgs e)
{
// Bind it first
base.OnItemDataBound (e);
// Confirm delete enabled?
if (!confirmdel) return;
// Attach javascript confirmation to the delete button
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
{
if (delcol != -1)
{
e.Item.Cells[delcol].Attributes.Add("onclick", "return confirm('Are you sure?')");
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.