Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I am using Visual Web Developer 2010 Express to develop a website.
On one of my web forms I have a filter where the user can enter fields (eg Lastname, Firstname, HospNumber) to search for patients. The patients matching those filter criteria are then loaded from the database and displayed in a GridView.
The user can now select one of the patient records and when he clicks on a Button he is directed to another page where all the details (including treatment details) of the patient is displayed and can be edited.

I would like to ensure that the user has actually selected a row in the GridView before clicking the Button. What I would like is client side script that when the user clicks the Button it checks to see if something has been selected. If nothing selected an alert must pop up. If something has been selected then the user is directed normally to the Button’s PostbackURL.

How do I check on client-side if something has been selected in the GridView?

The script is something like this

<script type="text/javascript">
    function ClientSideCode(sender, args) {
        //check if something selected
        
        //how do I check if something selected
        /*
        if (selected == true) {
            return true;
        }
        else {
            alert("Please select a patient first");
            return false;
        }
        */
    }
</script>


Thank you for the help.

Kobus
Posted

You may wish to read the following article. The first one from Sacha is selecting a row from a GridView, but he is doing it with Javascript and you will likely be able to garner the correct processes from his code which is usually really clean and easy to follow as are his excellent articles.

Using JavaScript To Select GridView Rows[^]
 
Share this answer
 
Comments
thatraja 9-Jul-11 15:22pm    
Also nice article, 5!
 
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