Sunday, August 2, 2009

Code to add JavaScript confirmation dialog to a button in a datagrid




Here is the code.It is free like "free beer".If you have question send me email at johnstalley@live.com.Remember datagrid index it 0 based.
NB You could add another parameter to the function that will execute when click=ok



public static void AddConfirm(DataGrid theGrid, int columnNumber, string question)
{
//for each row in the DataGrid
foreach(DataGridItem item in theGrid.Items)
{
//for each webcontrol in the column
foreach(WebControl control in item.Cells[columnNumber].Controls)
//if it is a LinkButton or Button
{
if(control is LinkButton || control is Button)
//add the attribute
control.Attributes.Add("OnClick", " javascript:return confirm('" + question + "');");
}
}
}

No comments:

About Me

My photo
Raleigh, NC, United States
I am a software developer based in Raleigh,NC,USA.I design softwares and systems ;i also do consulting for companies worldwide.I program with these languages:VB.NET 2003/2005/2008;C#;Java(fun),SQL(200,2005,2008);ASP.NET 2.0/3.5;ASP.NET AJAX;ASP.NET MVC;JavaScript;JQuery;Windows Workflow Foundation;Web Services.I have 4 years + in programming.