Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6177755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:19:57+00:00 2026-05-24T00:19:57+00:00

In my web application (asp.net & vb code), I had two different gridview. Each

  • 0

In my web application (asp.net & vb code), I had two different gridview.
Each gridview had checkbox to select records for batch update.
And then there are two button for batch update, one for Gridview 1 and Gridview 2.

I need to validate user had checked checkbox when click corresponding batch update button.

my code is work that it can prompt error msg if no checkbox checked when click corresponding batch update button.

But i found there is a error. For example, when I checked gridview2 checkbox and then clicked gridview1 batch update button, it cannot prompt any error msg, seems that my javascript cannot identify the checkbox related to another gridview.

the following is my code:
Javascript Code:

function IsSelectedAtleastOneOT() {
    var loTable1 = document.all("<%=Gridview1.ClientID%>"); // GridView Name        
    count1 = 0;
    with (document.forms[0]) {
        for (var i = 0; i < elements.length; i++) {
            var e1 = elements[i];
e.id.substring(e.id.lastIndexOf('_') + 1, e.id.length) == 'ControlName') // This is our control Name
              if (e1.type == "checkbox" && e1.checked == true) // This is our control Name
            {
                count1 += 1;
            }
        }
    }
    if (count1 == 0) {
        alert("You have not selected any record.");
        return false;
    }
    return true;
}

function IsSelectedAtleastOneActualDur() {
    var loTable2 = document.all("<%=Gridview2.ClientID%>"); // GridView Name
    count2 = 0;
    with (document.forms[0]) {
        for (var i = 0; i < elements.length; i++) {
            var e2 = elements[i];
            if (e2.type == "checkbox" && e2.checked == true ) 
            {
                count2 += 1;
            }
        }
    }
    if (count2 == 0) {
        alert("You have not select any record.");
        return false;
    }
    return true;
}

and the ASP.net code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize ="10" AutoGenerateColumns="False"
    CellSpacing="1" DataSourceID="SqlDataSource1" CellPadding="2" 
    AllowSorting="True" DataKeyNames="ot_key" >
    <Columns>
         <asp:TemplateField>

 <ItemTemplate>
 <asp:CheckBox ID="chkSelect" runat="server"   />
 </ItemTemplate>
  </asp:TemplateField>

        <asp:HyperLinkField DataNavigateUrlFields="action,ot_key" DataNavigateUrlFormatString="{0}?id={1}"
            DataTextField="post_code" HeaderText="Staff" SortExpression="post_code" meta:resourcekey="GridView1_post_code"/>
    .......

    </Columns>
    <EmptyDataTemplate>
        <span style="font-size: 14pt; color: #990000">
        <asp:Localize runat="server" ID="text_no_record" Text="No records found." meta:resourcekey="text_no_record" />
        </span>
    </EmptyDataTemplate>
</asp:GridView>

<asp:Button ID="btnBatchUpdate" runat="server" Text="Batch Recommend/Approve Overtime Work"  
          OnClick="btnBatchUpdate_Click" 
          OnClientClick="return IsSelectedAtleastOneOT();" Visible="false" 
    Width="277px" meta:resourcekey="btnBatchUpdate" />

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    CellSpacing="1" DataSourceID="SqlDataSource3" CellPadding="2" AllowSorting="True" DataKeyNames="actual_dur_key"  PageSize ="10">
    <Columns>
         <asp:TemplateField>

 <ItemTemplate>
 <asp:CheckBox ID="chkSelectActual_dur" runat="server" />
 </ItemTemplate>
  </asp:TemplateField>

        <asp:HyperLinkField DataNavigateUrlFields="action,actual_dur_key" DataNavigateUrlFormatString="{0}?id={1}"
            DataTextField="post_code" HeaderText="Staff" SortExpression="post_code" meta:resourcekey="GridView2_post_code"/>
.....

    </Columns>
    <EmptyDataTemplate>
        <span style="font-size: 14pt; color: #990000">
        <asp:Localize runat="server" ID="text_no_record" Text="No records found." meta:resourcekey="text_no_record" />
        </span>
    </EmptyDataTemplate>
</asp:GridView>       

<asp:Button ID="btnBatchUpdateActualDur" runat="server" Text="Batch Recommend/Approve Actual Duration"  
          OnClick="btnBatchUpdateActualDur_Click" 
          OnClientClick="return IsSelectedAtleastOneActualDur();" 
    Visible="false" Width="276px" meta:resourcekey="btnBatchUpdateActualDur"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:19:57+00:00Added an answer on May 24, 2026 at 12:19 am

    As per my understanding, you want to validate both grid views on click of both batch buttons. So just combine the two java scripts as one function or Just create another javascript function which will check both the functions and return a valid result like below

    function IsSelectedBoth()
    {
         if(IsSelectedAtleastOneOT() && IsSelectedAtleastOneActualDur())
            return true;
         else
            return false;
    }
    

    for both the buttons add the same onClientclick function as IsSelectedBoth()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.