I have a gridview within TabContainer control that has a checkbox item. I am firing the javascript to display an alert with the number of checkboxes selected.
I now want to update the label text on the screen with the count of selected checkboxes rather than showing the alert but I do not know how to reference the label.
See code below. Ideas or pointing me to a similar post would be appreciated.
<asp:Content ID="Content4" ContentPlaceHolderID="MasterContent" runat="server">
<script type="text/javascript">
function CheckBoxCount() {
var gv = document.getElementById("<%= gv02ROLE.ClientID %>");
var inputList = gv.getElementsByTagName("input");
var numChecked = 0;
for (var i = 0; i < inputList.length; i++) {
if (inputList[i].type == "checkbox" && inputList[i].checked) {
numChecked = numChecked + 1;
}
}
alert(numChecked);
<<< set text value for ID="statusLabel1" to replace this alert >>>
}
</script>
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" AutoPostBack="true">
.
<asp:TabPanel ID="TabREVROLE" runat="server" HeaderText="Open Review" Visible="false">
<ContentTemplate>
.
<asp:Label ID="statusLabel1" runat="server" Text=""></asp:Label>
<asp:GridView ID="gv02ROLE" runat="server" AllowPaging="True"
ShowHeaderWhenEmpty="True" AllowSorting="True" ShowHeader="true"
.
<asp:TemplateField HeaderText="Select" Visible="true" HeaderStyle-Width="10"
ItemStyle-Width="10">
<ItemTemplate>
<asp:CheckBox ID="selCheck" runat="server" CssClass="mychk"
Checked="false" Enabled="true"
onClick="javascript:CheckBoxCount()"/>
</ItemTemplate>
</asp:TemplateField>
document.getElementById("statusLabel1").value = numChecked
Why not simply:
function CheckBoxCount() {
var gv = document.getElementById("<%= gv02ROLE.ClientID %>"),
inputList = gv.querySelectorAll('input[type=checkbox]:checked'),
textProp = 'textContent' in document ? 'textContent' : 'innerText';
document.getElementById('statusLabel1')[textProp] = inputList.length;
}
References:
I briefly saw an initial answer on this to use this code:
`document.getElementById('<%=statusLabel1.ClientID%>').innerHTML = numChecked`
This solution worked. thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.