应用jQuery的数据表插件ASP GridView控件 [英] Apply Jquery DataTables plugin to ASP GridView
问题描述
我以前用这个插件在PHP,所以我想我会再次使用它为我的ASP项目。
I've used this plugin before in PHP so I thought I'll use it again for my ASP project.
出于某种原因,它不与我的GridView控件工作。
For some reason it doesn't work with my GridView control.
JavaScript的块:
javascript block:
<link type="text/css" href="../scripts/demo_table.css" rel="stylesheet" />
<script type="text/javascript" language="javascript" src="../scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" language="javascript" src="../scripts/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$(".gvv").dataTable();
});
</script>
的GridView code:
Gridview code:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False"
DataKeyNames="Prop_No" DataSourceID="testtt" CssClass="gvv">
我做得不对或数据表不能用于ASP控制?
Am I doing something wrong or DataTables can't be used for ASP controls?
推荐答案
的问题是,GridView控件不添加&LT; THEAD&GT;
元素,但只是把头一行到&LT;身体GT;
生成的表,而数据表插件的部分要求&LT; THEAD&gt;在
部分表。尝试使用以下脚本:
The problem is that GridView control doesn't add <thead>
element but just put the header row into <body>
section of generated table whereas the Data Table plugin requires a <thead>
section in a table. Try to use following script:
$(function () {
$(".gvv").prepend( $("<thead></thead>").append( $(this).find("tr:first") ) ).dataTable();
});
P.S。你也可以使用那些并不像中继器或ListView
P.S. also you can use controls those don't rendering with default layout like Repeater or ListView
这篇关于应用jQuery的数据表插件ASP GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!