Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want that after clicking a hyperlink "delete" located at each row of my gridview which lists trainings that i check if a trainee wasn't assign to the training concerned by the delete, then display a alert message if there is any trainee assigned to the training and if not to delete the training
Posted

Coding need to be done at rowdatacommand event of gridview

when the command arg is delete create a trainee object of same type what u have taken in ur case ( i hope you must have taken label in this case )
check if the text is not present or what ever ur logic is to check if trainee present or not
then check if (!traineepresent)
{
call javascript to display ur message from code behind.
}

VB
ScriptManager.RegisterStartupScript(
                        this,
                        typeof(string),
                        "allertmessagefunctionname",
                        "allertmessagefunctionname();",
                        true);


Hope the solution will work for you
 
Share this answer
 
i want that after clicking a hyperlink "delete" located at each row of my gridview which lists trainings that i check if a trainee wasn't assign to the training concerned by the delete
For adding a delete prompt on a datatable (looks like its going to be a datagrid in UI), you would need to bind the javascript to prompt for this alert during the ItemDataBound/RowDataBound event of the datagrid.

In this event, while the data is binded row by row - add something like:
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
    "confirm('Are you sure you want to delete this record')"); 


Alternatively,
if the link button in ItemTemplate of datagrid has OnclientClick event exposed (which is present in ASP.NET2.0 onwards), you can add something like:
OnClientClick = 'return confirm("Are you sure you want to delete this entry?");' 


Refer: MSDN: Adding Client-Side Confirmation when Deleting[^]


hen display a alert message if there is any trainee assigned to the training and if not to delete the training
For this, just show the thing in a label text. Showing it in an alert window would not be good idea for the purpose. Once DB update fails, show that as a red label text on the page.
 
Share this answer
 
you must be doing all the delete logic processing on server side. So you problem basically boils down to showing a messagebox(alert) to the user on some conditions that are met on serverside.

I think you can find this useful for your scenario

A Windows Form like MessageBox for ASP.NET Website[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900