<script language="JavaScript"> <!-- function SymError() { return true; } window.onerror = SymError; //--> </script> <script lang="JavaScript"> var total = 0 function countchecked(element){ if (element.checked==true) total++ else total-- } </script>For your button:
<INPUT type="button" value="Button" onclick="alert('There are '+total+' items selected');">In the Code-behind:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { System.Web.UI.WebControls.CheckBox myControl = (System.Web.UI.WebControls.CheckBox)e.Item.FindControl("MyCheckBox"); if(myControl!=null) { myControl.Attributes.Add("onClick","countchecked("+myControl.ClientID+")"); } }>I have a datagrid on a Web form with a checkbox in column 1, allowing users to select multiple records to be deleted. I also have a delete button on the form. When the user clicks that button, I want to display a Javascript confirm dialog box that would say something like "OK to delete the 5 selected records?".