像在ASP.NET应用程序中筛选Excel

我有一个已经运行的asp.net(非MVC)Web窗体应用程序。 它有一个gridview。

<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,但无法在我的项目上实现…

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

既然你打开使用jQuery,我会强烈build议DataTables http://datatables.net/ 。 这看起来类似于jqwidgets(但我不知道这个框架)。 我对数据表的使用经验是,使用起来非常简单,高度可configuration,有据可查并且快速闪电,用于过滤等。

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

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

  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); }