是否可以将DataTables列筛选器加载项与网格视图一起使用

本文关键字:网格 视图 一起 加载项 DataTables 筛选 是否 | 更新日期: 2023-09-27 18:22:31

我正在尝试在预渲染期间为定义tfoot部分和表行。有没有一种方法可以使用DataTables列过滤器插件定义文本输入,但我无法生成tfoot表行。我错过了什么?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Home
{
    public partial class Glossary : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.PreRender += new EventHandler(GridView1_PreRender);
        }
        protected void GridView1_PreRender(object sender, EventArgs e)
        {
           if (GridView1.Rows.Count > 0)
           {
             //forces grid to render thead/th elements 
             GridView1.UseAccessibleHeader = true; 
             GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
             GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
           }
}
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
}
}

这是当前表单的代码。我想知道是不是出了什么问题。

<%@ 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">Glossary</title>
    <style type="text/css" media="all">
        @import "DataTables-1.9.4/DataTables-1.9.4/media/css/jquery.dataTables_themeroller.css";
        #form1 {
            width: 100%;
        }
    </style>        
    <script src="JQuery-DataTables-ColumnFilter/media/js/jquery.dataTables.columnFilter.js"></script>
        <script src="DataTables-1.9.4/DataTables-1.9.4/media/js/jquery.js"></script>
        <script src="DataTables-1.9.4/DataTables-1.9.4/media/js/jquery.dataTables.js"></script>

        <script>
            $(document).ready(function () {
                $('#<%=GridView1.ClientID%>').dataTable()
                     .columnFilter();
            });
        </script>
    </head>
<body>
    <form id="form1" runat="server">
    <div style="background: #A0A0A0">
        <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
                <asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" Height="111px" Width="213px" style="margin-left: 0px; margin-right: 4px;">
                    <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
                    <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
                    <TextBoxStyle Font-Size="0.8em" />
                    <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
                </asp:Login>
            </AnonymousTemplate>
        </asp:LoginView>
        </div>
        <asp:SqlDataSource ID="TedGlossary" runat="server" ConnectionString="<%$ ConnectionStrings:Glsry_Taylor %>" SelectCommand="SELECT * FROM [Glossary] ORDER BY [TermText]"></asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="TermText,DefNbr,DefVerNbr" DataSourceID="TedGlossary" 
            EnableSortingAndPagingCallbacks="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
             AutoGenerateColumns="False" AutoGenerateEditButton="False" style="margin-right: 0px" Width="100%" Height="332px">               


            <Columns>
                <asp:BoundField DataField="TermText" HeaderText="Term" ReadOnly="True" SortExpression="Term" />
                <asp:BoundField DataField="DefNbr" HeaderText="Number" ReadOnly="True" SortExpression="DefinitionNumber" />
                <asp:BoundField DataField="DefVerNbr" HeaderText="Version" ReadOnly="True" SortExpression="DefinitinonVersionNumber" />
                <asp:BoundField DataField="DefText" HeaderText="Definition" SortExpression="Definition" />
                <asp:BoundField DataField="AmplifyingExplanationText" HeaderText="Amplifying Explanation" SortExpression="AmplifyingExplanationText" />
                <asp:BoundField DataField="SeeAlsoText" HeaderText="See Also" SortExpression="See Also" />
                <asp:BoundField DataField="AuthoritativeSrcText" HeaderText="Authoritative Source" SortExpression="AuthoritativeSrcText" />
                <asp:BoundField DataField="ScopeName" HeaderText="Scope" SortExpression="Scope" />
                <asp:BoundField DataField="DomnName" HeaderText="Domain" SortExpression="Domain" />
                <asp:BoundField DataField="GovernanceStateName" HeaderText="Governance State" SortExpression="GovernanceStateName" />
                <asp:BoundField DataField="LastUpdtTimestamp" HeaderText="Last Updated" SortExpression="LastUpdtTimestamp" />
            </Columns>

            <FooterStyle BackColor="Silver" />

        </asp:GridView>

    </form>

</body>
</html>

是否可以将DataTables列筛选器加载项与网格视图一起使用

您需要将Gridview的属性"ShowFooter"设置为True。通过默认将其设置为错误

<asp:GridView ID="GridView1" runat="server" ShowFooter="True" />