异常而结合jQuery的数据表到GridView控件 [英] Exception while binding jQuery datatable to gridview

查看:245
本文介绍了异常而结合jQuery的数据表到GridView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图jQuery的数据表中绑定到GridView控件。它抛出异常。

表必须包含行部分在头部,身体,那么页脚秩序。

步骤

1)JavaScript调用

 <脚本类型=文/ JavaScript的字符集=utf-8>
/ *为字符串排序定义了两个自定义功能(ASC和DESC)* /
  $(文件)。就绪(函数(){
    / *使用我们的自定义排序函数建立与第三列DataTable中* /
    $('#gvInitiavtives)。dataTable的({
        aaSorting:[[0,'递增']
    });
});

2)的GridView

 < ASP:GridView控件ID =gvInitiavtives=服务器WIDTH =100%的CssClass =网格
                     RowStyle-WIDTH =30像素的AutoGenerateColumns =false的HeaderStyle-的CssClass =GridHeaderRowStyle-的CssClass =的GridItemAlternatingRowStyle-的CssClass =GridAltItem的DataKeyNames =InitiativeIdxAllowSorting =真的ClientIDMode =静态>
                < EmptyDataRowStyle边框样式=无边框宽度=0像素/>
                < EmptyDataTemplate>
                    < ASP:标签ID =lblNorecId=服务器文本=对不起!您请求的记录都没有找到,请尝试其他搜索条件。字体粗体=真前景色=红FONT-名称=宋体FONT-SIZE =小>< / ASP:标签>
                < / EmptyDataTemplate>
                <柱体和GT;
                    < ASP:BoundField的数据字段=BusinessUnit的HeaderText =HeaderStyle换行=false的HeaderStyle-Horizo​​ntalAlign =NotSetSORTEX pression =BusinessUnit/>
                    < ASP:的TemplateField>
                    <&ItemTemplate中GT;                    < ASP:标签ID =lblInitiaiveName=服务器文本='<%#绑定(InitiativeName)%>'工具提示='<%#的String.Format({0} {1}的eval(计划),评估和演示(InitiativeDescription))%GT;' >< / ASP:标签>
                    < / ItemTemplate中>
                    < / ASP:的TemplateField>
---
---
< /专栏>
            < / ASP:GridView的>

3)$ C $后面

ç

 保护无效Page_ preRender(对象发件人,发送System.EventArgs)
{
    // jQuery的数据表支持
    如果(gvInitiavtives.Rows.Count大于0){
        gvInitiavtives.UseAccessibleHeader = TRUE;
        gvInitiavtives.HeaderRow.TableSection = TableRowSection.TableHeader;
    }}

4)异常

 在'/'应用程序的服务器错误。
-------------------------------------------------- ------------------------------该表必须包含的头,身体,那么页脚定单行部分。
说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。异常详细信息:System.Web.HttpException:该表必须包含标题,正文的定单行部分,然后页脚。源错误:当前Web请求的执行过程中生成了未处理的异常。有关异常的来源和位置信息可以使用异常堆栈跟踪下面确定。堆栈跟踪:
[HttpException(0x80004005的):该表必须包含标题顺序排段,身体,那么页脚。]
   System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter的作家)8790317
   System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter的作家)+32


解决方案

更改code这样的

<$p$p><$c$c>$('[id*=gvInitiavtives]').$p$ppend($(\"<thead></thead>\").append($(this).find(\"[id*=gvInitiavtives] TR:第一个)))的dataTable({
aaSorting:[[0,'递增']
    });

I am trying to bind jquery datatable to gridview. It throws exception.

"The table must contain row sections in order of header, body, then footer. "

Steps

1) JavaScript call

<script type="text/javascript" charset="utf-8">
/* 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:GridView ID="gvInitiavtives" runat="server" Width="100%" CssClass="Grid" 
                     RowStyle-Width="30px" AutoGenerateColumns="false" HeaderStyle-CssClass="GridHeader"  RowStyle-CssClass="GridItem" AlternatingRowStyle-CssClass="GridAltItem"  DataKeyNames="InitiativeIdx" AllowSorting="true" ClientIDMode="Static" >
                <EmptyDataRowStyle BorderStyle="None" BorderWidth="0px" />
                <EmptyDataTemplate>
                    <asp:Label ID="lblNorecId" runat="server" Text="Sorry! Your requested records are not found, please try with other search criteria." Font-Bold="true" ForeColor="red" Font-Names="Arial" Font-Size="small"></asp:Label>
                </EmptyDataTemplate>
                <Columns>
                    <asp:BoundField DataField="BusinessUnit" HeaderText="" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="NotSet" SortExpression="BusinessUnit" />
                    <asp:TemplateField>
                    <ItemTemplate>

                    <asp:Label ID="lblInitiaiveName" runat="server" Text='<%# Bind("InitiativeName") %>' ToolTip ='<%# String.Format("{0} ; {1}",Eval("Initiative"), Eval("InitiativeDescription")) %>' ></asp:Label>
                    </ItemTemplate>
                    </asp:TemplateField>
---
---
</Columns>
            </asp:GridView>

3) code behind

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) Exception

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

解决方案

Change code like this

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

这篇关于异常而结合jQuery的数据表到GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆