【问题标题】:Excel like filtering in ASP.NET applicationExcel 类似 ASP.NET 应用程序中的过滤
【发布时间】:2014-12-12 12:24:42
【问题描述】:

我有一个已经在运行的 asp.net(非 MVC)Web 表单应用程序。 它有一个网格视图。

<asp:GridView ID="gvPendingInvoices" runat="server" AutoGenerateColumns="false" Width="60%" AllowPaging="true" AllowSorting="true"
        CellPadding="4" OnPageIndexChanging="gvPendingInvoices_PageIndexChanging" OnRowDataBound="gvPendingInvoices_RowDataBound">
        <PagerStyle CssClass="gridView_PaggerStyle" HorizontalAlign="Left" />
        <HeaderStyle CssClass="gridView_HeaderStyle" HorizontalAlign="Left" />
        <SelectedRowStyle CssClass="gridView_SelectedRowStyle" />
        <FooterStyle CssClass="gridView_FooterStyle" />
        <PagerStyle HorizontalAlign="Left" />
        <AlternatingRowStyle CssClass="gridView_AlternatingRowStyle" />
        <PagerSettings PageButtonCount="10" Position="TopAndBottom" />
        <RowStyle BorderStyle="None" CssClass="gridView_RowStyle" />
        <Columns>
            <asp:TemplateField HeaderText="ProjectId" Visible="false">
                <ItemTemplate>
                    <asp:Label runat="server" ID="lblProjectId" Text='<%# Bind("ProjectId") %>' />
                </ItemTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="Project" ItemStyle-Width="20%">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lblProject" Text='<%# Bind("ProjectName") %>' OnClick="OnClickProjectName" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Project Manager" ItemStyle-Width="30%">
                <ItemTemplate>
                    <asp:Label runat="server" ID="lblName" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%">
                <ItemTemplate>
                    <asp:LinkButton runat="server" Text="Notify" ID="lbNotify" OnClick="Notify"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            No Record Found .</EmptyDataTemplate>
    </asp:GridView>

现在我想在这段代码中添加类似过滤的 excel ......类似这样的东西

http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm#demos/jqxgrid/filtering.htm

我已经下载了这个 JQuery,但无法在我的项目中实现它...

还有其他方法可以在我的应用程序中实现过滤吗?

【问题讨论】:

标签: c# jquery asp.net excel gridview


【解决方案1】:

由于您愿意使用 jQuery,我强烈建议您使用 DataTables http://datatables.net/。 这看起来类似于 jqwidgets(但我不知道那个框架)。我对 DataTables 的体验是,它非常易于使用、高度可配置、文档完善且速度极快,可用于过滤等。

我也非常喜欢使用 AJAX 更新表格的支持,它允许您修改单元格、检测到修改并自动调用自定义页面来执行更新。支持所有 asic Excel 功能,扩展性强。

我实际上很少在 ASP.NEt 中使用 GridView。我编写了一些 C# 代码来生成与 DataTables 兼容的 HtmlTable。我在下面编写了方便的扩展方法,它将 DataTable 转换为与 DataTables 框架兼容的 Html。现在,我可以轻松地为任何 DataTable 使用快速的客户端处理。应该直接使用下面的方法以及 DataTables 文档中的示例之一。

   public static string ToHtmlTable(this DataTable t,string cssClass="",string id=null,
            bool includeTHead=true,bool includeTBody=true,bool includeFooter=false,string trIDCol=null)
        {
            MemoryStream ms = new MemoryStream();
            XmlWriter x = new XmlTextWriter(ms, Encoding.Default);
            x.WriteStartElement("table");
            x.WriteAttributeString("class", cssClass);
            if (id != null)
            {
                x.WriteAttributeString("id", id);

            }

            x.WriteNewline(); x.WriteNewline();
            if (includeTHead)
            {
                x.WriteStartElement("thead");
            }
            x.WriteStartElement("tr");

            foreach (DataColumn dc in t.Columns)
            {
                x.WriteElementString("th", dc.ColumnName);

            }
            x.WriteEndElement();

            if (includeTHead)
            {
                x.WriteEndElement();
            }

            x.WriteNewline(); 
            x.WriteNewline();
            InsertTableRows(t, x, includeTBody,trIDCol);
            if (includeFooter)
            {
                x.WriteStartElement("tfoot");
                x.WriteStartElement("tr");
                foreach (DataColumn dc in t.Columns)
                {
                    x.WriteElementString("th", dc.ColumnName);

                }
                x.WriteEndElement();
                x.WriteEndElement();
            }


            x.WriteEndElement();
            x.Flush();
            return StreamUtils.StreamToString(ms);
        } 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 2015-12-19
    • 1970-01-01
    • 2018-03-20
    相关资源
    最近更新 更多