473,494 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need a client side script to update gridview row data when checkbox is checked.

12 New Member
I have a gridview that contains a checkbox and a Label on each row. I am using client side javascript to display a count of checkboxes checked to avoid post backs. I now also want to get/update the Label value on each row when the checkbox is checked or unchecked - but can't quite figure it out. Any help or direction to a similar post would be appreciated. See current code below:

JavaScript code:
Expand|Select|Wrap|Line Numbers
  1. function CheckBoxCount() {
  2.    var gv = document.getElementById("<%= gv02ROLE.ClientID %>");
  3.    var inputList = gv.getElementsByTagName("input");
  4.    var numChecked = 0;
  5.  
  6.    for (var i = 0; i < inputList.length; i++) {
  7.       if (inputList[i].type == "checkbox" && inputList[i].checked) {
  8.          numChecked = numChecked + 1;
  9.       }
  10.    }
  11.    if (numChecked == 0) { 
  12.       document.getElementById('<%=statusLabel1.ClientID%>').innerHTML = ' '; 
  13.    }
  14.    else { 
  15.          document.getElementById('<%=statusLabel1.ClientID%>').innerHTML = numChecked + ' Items Selected.'; 
  16.     }
  17. }
  18.  
Gridview:
Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField HeaderText="Select" Visible="true">
  2. <ItemTemplate>
  3.     <asp:CheckBox ID="rolSelChk" runat="server" CssClass="mychk" Checked="false" Enabled="true" onClick="javascript:CheckBoxCount()"/>
  4. </ItemTemplate>
  5. </asp:TemplateField>
  6.  
  7. <asp:TemplateField HeaderText="Status" Visible="true">
  8. <ItemTemplate>
  9.    <asp:Label ID="rolStatus" runat="server" Text="" CausesValidation="False"></asp:Label> 
  10. </ItemTemplate>
  11. </asp:TemplateField>
  12.  
Dec 10 '14 #1
1 1708
Frinavale
9,735 Recognized Expert Moderator Expert
Add a parameter to the JavaScript method CheckBoxCount and pass this to the method in the onClick event.

That way you have a reference to the checkbox that was clicked in your JavaScript code.

From there you can walk up the DOM to find the row that checkbox belongs to so that you can then find the label that you want to update.

-Frinny
Dec 11 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1358
by: Mario T. Lanza | last post by:
Seasoned ASP Developers, I have developed an ASP page that displays multiple rows of data with which the user may work. As each row is updated, the graphical info displayed immediately beside...
2
2159
by: Bill Manring | last post by:
In an ASP.NET web application, I am using the standard list box server control and I am adding items to with client side script. When the page posts back, the added items are not available on the...
1
2095
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML =...
6
3314
by: Guadala Harry | last post by:
I have some client-side JavaScript that, among other things, calculates the value of a variable (myVar). On the server I have a stored procedure that needs to somehow receive as an input parameter...
1
2488
by: Jordan | last post by:
I'm trying to initiate Postback from client-side script, and here's what I have that doesn't work: I have an <asp:Button> on the same page named btnSave that the user can click (its functionality...
3
1205
by: Yama | last post by:
Hi, I have a datagrid with several columns and a single column containing a checkbox. The grid has some client-side javascript and style sheet that allows rollover change of row color. I...
3
1428
by: EC | last post by:
I have a web control button with which runs a client side script before it the autopostback using the onclick event. It is working fine when the user clicks it. What I would like to do is...
4
1190
by: Mantorok | last post by:
Hi all I have a ListControland it is updated by client-side script, the client script adds a new item and gives it a value and a key. The problem is when it's posted back the server the items...
6
3671
by: sgulciny | last post by:
hi friends; I have problem about sql server insert and update in client side. I am coding windows application with c#.When I run my code in database server computer all is fine.I can see data,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.