.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Javascript to check that only single record is selected in the grid

Posted By:Maverick       Posted Date: July 21, 2011    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

Javascript to check that only single record is selected in the grid
 

Hello All,

The javascript below will check that only single record is selected from the grid while edit operations.

function CheckEditMode(checkBox) {
 
    var frm = document.forms[0];
    var flag = false;
    var cnt = 0;
 
    for (var i = 0; i < document.forms[0].length; i++) {
        if (document.forms[0].elements[i].id.indexOf(checkBox) != -1) {
            if (document.forms[0].elements[i].checked) {
                flag = true
                cnt = cnt + 1;
            }
        }
    }
    if (cnt > 1) {
        ////If multiple records are selected for edit.
        alert('Please select single record.');
        document.getElementById(hiddenField).value = 0;
        return false;
    }

The argument checkbox means the checkbox client id of the gridview

Hope it helps.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend