Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Javascript confirm dialog box
Message
 
To
23/01/2003 12:11:43
Gary Otte
California Youth Authority
Sacramento, California, United States
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00744768
Message ID:
00745148
Views:
15
Hi Gary,

Here is one approach to get the dialog box to appear with the information. You can dynamically add an onClick to each checkbox control to call a javascript function that keeps track of the number of checked rows. Then on a button you can use this information to display the amount.
<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?".
>
>I understand how to display a dialog box saying "OK to delete the selected records?", but I would like to include the selected record count in the dialog (e.g., "5").
>
>Any thoughts?
>
>TIA,
>Gary
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform