如何通过单击按钮检查 gridview 列中复选框的状态 [英] how to check status of checkboxes in gridview columns on click of button

查看:23
本文介绍了如何通过单击按钮检查 gridview 列中复选框的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

T 在 gridview 中使用了复选框列.单击链接按钮时,应检查 gridview 中的复选框是否已选中.如果未选中任何复选框,则应显示警报(至少选中一个复选框").

T have used checkbox column in gridview. On click of a linkbutton, it should be checked that checkboxes in gridview are checked or not. If none check box is checked then it should display alert("Check at leat one check box").

推荐答案

我找到了答案.及其工作...

I found the answer. and its working...

函数 checkBoxselectedornot(){

function checkBoxselectedornot() {

       var frm=document.forms['aspnetForm'];
       var flag=false;
       for(var i=0;i<document.forms[0].length;i++)
       {
           if(document.forms[0].elements[i].id.indexOf('chkDownloadSelectedEvent')!=-1)
           {
                 if(document.forms[0].elements[i].checked)
                 {
                      flag=true
                 }  
           }
       } 
      if (flag==true)
      {
        return true
      }else
      {
        alert('Please select at least one Event.')
        return false
      }

}

和 girdview 代码是...

and girdview code is...

            <asp:BoundField ItemStyle-Width ="100px" DataField ="EventStartDate" DataFormatString ="{0:g}" HeaderText ="<%$ Resources:stringsRes, ctl_EventList_StartDate %>" SortExpression ="EventStartDate" HtmlEncode ="true" ItemStyle-Wrap ="false" />
            <asp:BoundField ItemStyle-Width="100px" DataField="EventDate" DataFormatString="{0:g}" HeaderText="<%$ Resources:stringsRes, ctl_EventList_Date %>"  SortExpression="EventDate" HtmlEncode="true" ItemStyle-Wrap="false" />
            <asp:ButtonField ItemStyle-Width="150px" ButtonType="Link" DataTextField="EventName" HeaderText="<%$ Resources:stringsRes, ctl_EventList_Event %>"  SortExpression="EventName" CommandName="show_details" CausesValidation="false" />
            <asp:BoundField DataField="EventLocation" HeaderText="<%$ Resources:stringsRes, ctl_EventList_Location %>" SortExpression="EventLocation" />
            <asp:TemplateField HeaderText ="Select">
            <ItemTemplate >
                <asp:CheckBox ID="chkDownloadSelectedEvent" runat ="server" AutoPostBack ="false" Onclick="eachCheck();"/>                   

            </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle Height="25px" />
        <HeaderStyle Height="30px"/>
    </asp:GridView>

还有一个链接按钮....

and there is a link button ....

这篇关于如何通过单击按钮检查 gridview 列中复选框的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆