检查是否在客户端选择了GridView Row?

问题描述:

你好

我正在使用Visual Web Developer 2010 Express开发网站.
在我的一个Web表单上,我有一个过滤器,用户可以在其中输入字段(例如,姓氏,名字,医院编号)来搜索患者.然后,从数据库中加载符合那些过滤条件的患者,并显示在GridView中.
用户现在可以选择一个患者记录,当他单击按钮时,他将被带到另一个页面,该页面上将显示患者的所有详细信息(包括治疗详细信息)并可以对其进行编辑.

我想确保用户在单击按钮之前实际上已经在GridView中选择了一行.我想要的是客户端脚本,当用户单击按钮"时,它将检查是否已选择某些内容.如果未选择任何内容,则必须弹出警报.如果选择了某些内容,则通常会将用户定向到Button的PostbackURL.

如何在客户端检查GridView中是否已选择某些内容?

脚本是这样的

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>



谢谢您的帮助.

Kobus



Thank you for the help.

Kobus

您可能希望阅读以下文章. Sacha的第一个选择是从GridView中选择一行,但是他使用Javascript来完成这一工作,您可能将能够从他的代码中获得正确的过程,而这些代码通常是干净的,并且易于阅读,就像他的优秀文章一样.

使用JavaScript选择GridView行 [
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[^]


在这里

GridView内部复选框的客户端验证 [
Here you go

Client-Side Validation for the CheckBoxes Inside a GridView[^]