Question : Not answered How to call Javascript function when checkbox columns are checked

Hi,

I am using Gridclientselectcoiumn in my radgrid. I have a label in my commanditemtemplate.  When user checks checkbox i just want to show number of checkboxes selected in that label. Suppose If user selects 4 checkboxes i just want to show like Selected Records: 4.  Here is my code for that......

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
commanditemtemplate

<td align="right" style="width: 20%">
                                        Selected Records:<asp:Label ID="lblselTsks" Width="20px" Font-Size="10pt" Font-Bold="true"
                                            runat="server" Text="0"></asp:Label>
                                    </td>

Grid client select column....

<telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="3%"
                                ItemStyle-Width="3%">
                                <HeaderStyle Width="3%"></HeaderStyle>
                                <ItemStyle Width="3%"></ItemStyle>
                            </telerik:GridClientSelectColumn>

codebehind and JS

protected void rg200_DataBound(object sender, EventArgs e)
{
    foreach (GridDataItem item in rg200.MasterTableView.Items)
    {
        CheckBox chkBoxOne = (CheckBox)item.FindControl("ClientSelectColumn");
        if (chkBoxOne != null)
            chkBoxOne.Attributes.Add("onclick", "javascript:return SelectOne('" + chkBoxOne.ClientID + "')");
    }
}


            function SelectOne(id) {
            var count = 0;
            count = Number(document.getElementById('ctl00_PagePlaceholder_rg200_ctl00_ctl02_ctl00_lblselTsks').innerHTML);
            if (document.getElementById(id).checked == true) {
                if (!document.getElementById(id).disabled) {
                    count = count + 1;
                }
            }
            else if (document.getElementById(id).checked == false) {
                if (!document.getElementById(id).disabled) {
                    count = count - 1;
                }
            }
            document.getElementById('ctl00_PagePlaceholder_rg200_ctl00_ctl02_ctl00_lblselTsks').innerHTML = count;
        }


The problem is when i select checkbox  like 1 or more, the selected checkboxes count is not displaying. Its always showing Selected Records: 0.( See the image). Where am i doing wrong? How to resolve this issue. Any help should be appreciated.
Attachments:
 
Error Image
Error Image
 

Answer : Not answered How to call Javascript function when checkbox columns are checked

You should remove the following "else if" part in your code

else if (document.getElementById(id).checked == false) {
                if (!document.getElementById(id).disabled) {
                    count = count - 1;
                }
}

Because if you count the no of checkboxes that has checked and subtract  no of checkboxe that has unchecked, ultimate result will be 0 (zero)

-Kusala
Random Solutions  
 
programming4us programming4us