将jQuery数据绑定到gridview时出现exception

我正在尝试将jquery数据绑定到gridview。 它抛出exception。

“该表必须按标题,正文和页脚的顺序包含行部分。”

脚步

1)JavaScript调用

 /* Define two custom functions (asc and desc) for string sorting */ $(document).ready(function () { /* Build the DataTable with third column using our custom sort functions */ $('#gvInitiavtives').dataTable({ "aaSorting": [[0, 'asc'] }); }); 

2)Gridview

           <asp:Label ID="lblInitiaiveName" runat="server" Text='' ToolTip ='' >   --- ---   

3)代码背后

 protected void Page_PreRender(object sender, System.EventArgs e) { // support for jquery datatables if (gvInitiavtives.Rows.Count > 0) { gvInitiavtives.UseAccessibleHeader = true; gvInitiavtives.HeaderRow.TableSection = TableRowSection.TableHeader; } } 

4)例外

 Server Error in '/' Application. -------------------------------------------------------------------------------- The table must contain row sections in order of header, body, then footer. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The table must contain row sections in order of header, body, then footer. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [HttpException (0x80004005): The table must contain row sections in order of header, body, then footer.] System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer) +8790317 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 

改变这样的代码

 $('[id*=gvInitiavtives]').prepend($("").append($(this).find("[id*=gvInitiavtives] tr:first"))).dataTable({ "aaSorting": [[0, 'asc'] });