Adding new Button to GridView give an error in jquery.dataTables.min.js


I currently have a GridView and I'm trying to add a button. I'm able to add it but when I click on it I get this weird error on this line.

if(c.mData===a){var d=u(b,"sort")||u(b,"order"),e=u(b,"filter")||u(b,"search");


Unhandled exception at line 91, column 426 in http://localhost:23549/Scripts/jquery.dataTables.min.js

0x800a138f - Microsoft JScript runtime error: 'mData' is null or not an object

I've done a bit of research and I can't find this issue anywhere else. Other users are getting the same error but none of them use ASP. I tried changing some properties on the button. I also tried adding it has a ButtonField instead but I still get the same error.

<div class="datatable">
    <asp:GridView runat="server" ID="jobGridView" AutoGenerateColumns="False" BorderWidth="0px" GridLines="None" CssClass="table table-hover table-condensed font13" OnRowDataBound="jobGridView_RowDataBound" DataKeyNames="site_id,id" OnRowCommand="OnOff">
            <asp:BoundField DataField="site_id" meta:resourcekey="siteField" />
            <asp:BoundField DataField="id" meta:resourcekey="jobNameField" />
            <asp:BoundField DataField="job_start_date" meta:resourcekey="jobStartField" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />
            <asp:BoundField DataField="job_end_date" meta:resourcekey="jobEndField" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />
            <asp:BoundField DataField="job_duration" meta:resourcekey="jobDurationField" DataFormatString="{0:HH:mm:ss.fff}" />
            <asp:BoundField DataField="job_last_run_elapsed_time" meta:resourcekey="jobElapsedTimeField" />
            <asp:BoundField DataField="return_code" meta:resourcekey="returnCodeField" />
            <asp:BoundField DataField="return_description" meta:resourcekey="returnDescriptionField" />
            <asp:BoundField DataField="status_code" meta:resourcekey="statusField" />
            <asp:BoundField DataField="job_last_failure" meta:resourcekey="jobLastFailureField" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />
                    <asp:LinkButton ID="lnkSelect" runat="server" Text="View" OnClientClick='<%# GetOpenTabJavascript(DataBinder.Eval(Container.DataItem, "id"), DataBinder.Eval(Container.DataItem, "site_id"))%>' />
                    <asp:Button ID="Button1" runat="server" CommandName="OnOff" Text="Turn On/Off" ShowHeader="True" CommandArgument='<%# Eval("id") %>' />

 protected void OnOff(object sender, GridViewCommandEventArgs e)
            if (e.CommandName == "OnOff")
               //This part gets hit when debugging, error is after


If I remove the button everything works fine. (The LinkButton work)

I tried changing the type of event to RowEditing and RowUpdating. Same error.

Where should I start debugging to find out where the error comes from? Feel free to ask any questions.

asked on Stack Overflow Jan 30, 2017 by phil652 • edited Jan 30, 2017 by phil652

1 Answer


The error is being pretty straightforward in just letting you know jquery.dataTables is looking for an object named mData which is currently null and/or false.

Try giving your <div class="datatable"> an ID to match what dataTables is looking for.

That is, <div class="datatable" id="mData"> I'm not 100% sure that will do it, but your solution will be definitely in the neighborhood.

I've used dataTables a lot and tended to run into lots of annoying errors like this that just took debugging and banging my head on the desk some before I figured it out.

Seems like otherwise (can't really tell without debugging myself) your code would be fine--you just need to explicitly tell dataTables what mData is. If it's not on the <div>, maybe the button or GridView: honestly, too many variables for me to know for sure (unless you try some of these and have feedback! :))

answered on Stack Overflow Jan 30, 2017 by Fernando Rodriguez

User contributions licensed under CC BY-SA 3.0