1

I am having an issue with a Jquery click function and a javascript onclick funcion added using a gridview rowdatabound event. When the page is loaded the first time, the jquery click function works fine. But when the GridView Row is clicked and the javascript onclick function is triggered, the jquery click function doesn't work anymore and I get the following error:

"Input string was not in a correct format".

This is the script code, and I have the issue with the $('.guardar').click function.

    <script>
        function cargartabla() {
            $('#MainContent_GVTrabajadores').DataTable({
                "aaSorting": [],
                responsive: true,
                aLengthMenu: [
                    [10, 25, 50, 100, -1],
                    [10, 25, 50, 100, "Todo"]
                ],
                destroy: true,
            });
        }
        $(document).ready(function() {
            cargartabla();
            var oTable;
            $('.guardar').click(function () {
                var oSettings = oTable.fnSettings();
                oSettings._iDisplayLength = -1;
                oTable.fnDraw();
            });
            oTable = $('#MainContent_GVTrabajadores').dataTable();
        });

        //On UpdatePanel Refresh
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm != null) {
            prm.add_endRequest(function (sender, e) {
                if (sender._postBackSettings.panelsToUpdate != null) {
                    cargartabla();
                    var oTable;
                    $('.guardar').click(function () {
                        var oSettings = oTable.fnSettings();
                        oSettings._iDisplayLength = -1;
                        oTable.fnDraw();
                    });
                    oTable = $('#MainContent_GVTrabajadores').dataTable();
                }
            });
        };
    </script>

and this is the row click event added using the OnRowDataBound event handler.

protected void GVTrabajadores_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GVTrabajadores, "Select$" + e.Row.RowIndex);
        e.Row.Attributes["style"] = "cursor:pointer";
    }
}
DavidM
  • 307
  • 2
  • 6
  • 22

0 Answers0