R
Ron Clarke
I have a small web app that displays data from a SQL Server database. Using
a DataGrid control on a page, the user can delete a row from the database.
This works fine. But I want to prompt the user for confirmation ("Are you
sure...") before deleting the record. How can I do this from the ASP.NET
code? Since the C# code is server-side, is there a way to display a Yes/No
type of message box and only take action if the users clicks the "Yes"
button? I'm new to web development, so any and all help is appreciated.
Here is the deletion message handler; I want to prompt the user for
confirmation before the deletion code executes:
private void dgridProfiles_Delete(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
[** How do I prompt the user here??]
[If user said yes, then...]
String profID = e.Item.Cells[0].Text.Trim();
String deleteCmd = "DELETE from Profile where ProfileID = @profID";
string connstr =
ConfigurationSettings.AppSettings["BLConnectionString"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand(deleteCmd, connection);
myCommand.Parameters.Add(new SqlParameter("@profID", SqlDbType.Char,
10));
myCommand.Parameters["@profID"].Value =
dgridProfiles.DataKeys[(int)e.Item.ItemIndex];
connection.Open();
try
{
myCommand.ExecuteNonQuery();
dgridProfiles.EditItemIndex = -1;
LabelMessageArea.Text = "Profile deleted.";
}
catch (SqlException )
{
LabelMessageArea.Text = "ERROR: Could not delete record.";
}
finally
{
connection.Close();
}
BindGrid();
}
[end code sample]
Thanks!
a DataGrid control on a page, the user can delete a row from the database.
This works fine. But I want to prompt the user for confirmation ("Are you
sure...") before deleting the record. How can I do this from the ASP.NET
code? Since the C# code is server-side, is there a way to display a Yes/No
type of message box and only take action if the users clicks the "Yes"
button? I'm new to web development, so any and all help is appreciated.
Here is the deletion message handler; I want to prompt the user for
confirmation before the deletion code executes:
private void dgridProfiles_Delete(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
[** How do I prompt the user here??]
[If user said yes, then...]
String profID = e.Item.Cells[0].Text.Trim();
String deleteCmd = "DELETE from Profile where ProfileID = @profID";
string connstr =
ConfigurationSettings.AppSettings["BLConnectionString"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand(deleteCmd, connection);
myCommand.Parameters.Add(new SqlParameter("@profID", SqlDbType.Char,
10));
myCommand.Parameters["@profID"].Value =
dgridProfiles.DataKeys[(int)e.Item.ItemIndex];
connection.Open();
try
{
myCommand.ExecuteNonQuery();
dgridProfiles.EditItemIndex = -1;
LabelMessageArea.Text = "Profile deleted.";
}
catch (SqlException )
{
LabelMessageArea.Text = "ERROR: Could not delete record.";
}
finally
{
connection.Close();
}
BindGrid();
}
[end code sample]
Thanks!