mercredi 17 février 2016

onclick for checkbox returning undefined

I have a GridView where a column is a checkbox. In the database these checkboxes are dafaulted to one. So if the user unticks the checkbox I call a web method to update the database.

GridView code:

<asp:GridView  style="width:75%"  
                        ID="gvCVRTDetails" 
                        ShowHeaderWhenEmpty="true"
                        CssClass="tblResults" 
                        runat="server" 
                        OnRowDataBound="gvCVRTDetails_RowDataBound"                             
                        DataKeyField="ID" 
                        AutoGenerateColumns="false"
                        allowpaging="false"
                        AlternatingRowStyle-BackColor="#EEEEEE">
                        <HeaderStyle CssClass="tblResultsHeader" />
                        <Columns>
                            <asp:BoundField DataField="ChecklistID" HeaderText="ID" ></asp:BoundField> 
                            <asp:BoundField DataField="Description" HeaderText="Checklist Items"></asp:BoundField> 
                            <asp:BoundField DataField="Checked" HeaderText="OK"></asp:BoundField> 
                    </asp:GridView>

Code behind:

protected void gvCVRTDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                lookupCVRT work = (lookupCVRT)e.Row.DataItem;
                GridView gv = sender as GridView;             

                e.Row.Attributes.Add("ID", "gvCVRTDetails_" + work.ID);
                e.Row.Cells[0].Attributes.Add("onclick", "event.stopPropagation();");

                HtmlGenericControl lnkShowHide = (HtmlGenericControl)e.Row.FindControl("lnkShowHide");
                HyperLink ChecklistItem = (HyperLink)e.Row.FindControl("ID");

                bool bAll = work.Checked;
                e.Row.Cells[4].Text = "<input type=\"checkbox\" " + ((bAll) ? "checked" : "") + "/>";
                e.Row.Cells[4].Attributes.Add("onclick", "UpdateCheckedBox(" + work.ID.ToString() + ", this.Checked);");
            }
        }

Javascript function:

function UpdateCheckedBox(ID, Checked) {
        alert(Checked);
        PageMethods.UpdateCheckUserControl(ID, Checked, OnUpdateSuccess, OnUpdateFail);
    }

But calling this.Checked is returning undefined instead of true or false. I also tried this.Value but that doesn't work either




Aucun commentaire:

Enregistrer un commentaire