有没有办法从SQL查询创建数据表并使用数据表jquery过滤?

时间:2013-07-11 16:31:34

标签: c# jquery asp.net datatables

我正在尝试从sql源创建一个数据表,我希望能够使用jquery datatables过滤器过滤结果。有没有办法用我所拥有的呢?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Glossary.aspx.cs" Inherits="Home.Glossary" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title spellcheck="true">Lexis Nexis Glossary</title>
    </head>
<body>
    <form id="form1" runat="server">
    <div style="margin-left: 720px">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    </div>

        <asp:SqlDataSource ID="TedGlossary" runat="server" ConnectionString="<%$ ConnectionStrings:Glsry_Taylor %>" SelectCommand="SELECT [TermText], [DefNbr], [DefVerNbr], [DefText], [AmplifyingExplanationText], [SeeAlsoText], [AuthoritativeSrcText], [ScopeName], [DomnName], [GovernanceStateName], [LastUpdtTimestamp] FROM [Glossary] ORDER BY [TermText]"></asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server"  AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"

             DataKeyNames="TermText,DefNbr,DefVerNbr" DataSourceID="TedGlossary" EnableSortingAndPagingCallbacks="True">

            <Columns>
                <asp:BoundField DataField="TermText" HeaderText="Term" ReadOnly="True" SortExpression="TermText" />
                <asp:BoundField DataField="DefNbr" HeaderText="Definition #" ReadOnly="True" SortExpression="DefNbr" />
                <asp:BoundField DataField="DefVerNbr" HeaderText="Definition Vers #" ReadOnly="True" SortExpression="DefVerNbr" />
                <asp:BoundField DataField="DefText" HeaderText="Definition" SortExpression="DefText" />
                <asp:BoundField DataField="AmplifyingExplanationText" HeaderText="Amplifying Explanation" SortExpression="AmplifyingExplanationText" />
                <asp:BoundField DataField="SeeAlsoText" HeaderText="See Also" SortExpression="SeeAlsoText" />
                <asp:BoundField DataField="AuthoritativeSrcText" HeaderText="Authoritative Source" SortExpression="AuthoritativeSrcText" />
                <asp:BoundField DataField="ScopeName" HeaderText="Scope Name" SortExpression="ScopeName" />
                <asp:BoundField DataField="DomnName" HeaderText="Domn Name" SortExpression="DomnName" />
                <asp:BoundField DataField="GovernanceStateName" HeaderText="Governance State" SortExpression="GovernanceStateName" />
                <asp:BoundField DataField="LastUpdtTimestamp" HeaderText="Last Update" SortExpression="LastUpdtTimestamp" />
            </Columns>


        </asp:GridView>

    </form>
    <script>
        $(function () {
            $('#<%=GridView1.ClientID%>').dataTable();
    });
</script>

</body>
</html>

我正在尝试从sql源创建一个数据表,我希望能够使用jquery datatables过滤器过滤结果。有没有办法用我所拥有的呢?

1 个答案:

答案 0 :(得分:1)

调用javascript时会发生什么?调试控制台窗口中的任何内容?

您应该将dataTable()调用函数附加到事件处理程序,如下所示:

 <script>
        $(document).ready(function () {
            $('#<%=GridView1.ClientID%>').dataTable();
    });
</script>

您是否检查过呈现的HTML元素以查看该表是否包含元素?我认为JS dataTable需要它。