如何通过单击按钮检查 gridview 列中复选框的状态

how to check status of checkboxes in gridview columns on click of button(如何通过单击按钮检查 gridview 列中复选框的状态)
本文介绍了如何通过单击按钮检查 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 列中复选框的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)