希望 永远是快乐的.

有一种沉默叫霸气,有一种内敛叫个性,有一种简单叫深遂,有一种不屑叫自我。

导航

过滤列表文档

Requirement:

   最近客户在列表文档库中上传了多很文档,如果他们需要看一个文档,要翻很多页才能找到,他们希望用A.B.C...Z 字母开头的进行过滤。当点A的时候,显示A开头的所有文档。

 

 

 

Solution:

   我想要实现这种功能有很多种方法,下面我给大家介绍我如何实现的这个功能。

 

    step1,我创建了一个叫Brand的View,这个 view专门来过滤文档的。

 

    step2,添加一个quickpart 容器webpart,用他来包装我们开发的过滤用户控件。

 

    User Control代码 如下:

 

    

  1<%@ Control Language="C#" Debug="true" %>
  2<%@ Import Namespace="Microsoft.SharePoint" %>
  3<%@ Import Namespace="System.Data"  %>
  4
  5<script runat="server">
  6    string redirectUrl="/BizDevMarketing/ImageVideoLibrary/Forms/AegisCompany.aspx?RootFolder=%2FBizDevMarketing%2FImageVideoLibrary%2FAegis%20Company%20Logos";
  7    protected void Page_Load(object sender, EventArgs e)
  8    {
  9        if (!IsPostBack)
 10        {
 11            SPSite mySite = null;
 12            SPWeb myWeb = null;
 13            try
 14            {
 15                SPSecurity.RunWithElevatedPrivileges(delegate()
 16                {
 17                    mySite = new SPSite(SPContext.Current.Site.ID);
 18                    myWeb = mySite.OpenWeb(SPContext.Current.Web.ID);
 19    
 20                    SPList oList = myWeb.Lists["Image & Video Library"];
 21                    SPView oView = oList.Views["AegisCompany"];
 22    
 23                    if (string.IsNullOrEmpty(this.Request["FitlerString"]))
 24                    {
 25                        if (!string.IsNullOrEmpty(oView.Query))
 26                        {
 27                            myWeb.AllowUnsafeUpdates = true;
 28                            oView.Query = "";
 29                            oView.Update();
 30                            myWeb.AllowUnsafeUpdates = false;
 31    
 32                            mySite = null;
 33                            myWeb = null;
 34                            this.Response.Redirect(redirectUrl, true);
 35                        }

 36                        else
 37                        {
 38                            All.ForeColor = System.Drawing.Color.Red;
 39                        }

 40                    }

 41                    else
 42                    {
 43                        ((LinkButton)this.FindControl(Request["FitlerString"])).ForeColor = System.Drawing.Color.Red;
 44                    }

 45                }
);
 46            }

 47            catch
 48            {
 49    
 50            }

 51            finally
 52            {
 53                mySite = null;
 54                myWeb = null;
 55    
 56            }
    
 57        }

 58    }

 59    protected void LinkButton_Click(object sender, EventArgs e)
 60    {
 61        LinkButton tempButton = (LinkButton)sender;
 62        SPSite mySite = null;
 63        SPWeb myWeb = null;
 64        try
 65        {
 66            SPSecurity.RunWithElevatedPrivileges(delegate()
 67            {
 68                mySite = new SPSite(SPContext.Current.Site.ID);
 69                myWeb = mySite.OpenWeb(SPContext.Current.Web.ID);
 70                myWeb.AllowUnsafeUpdates = true;
 71
 72                SPList oList = myWeb.Lists["Image & Video Library"];
 73                SPView oView = oList.Views["AegisCompany"];
 74                if (tempButton.CommandName != "ALL")
 75                {
 76                    oView.Query = "<Where><BeginsWith><FieldRef Name=\"FileLeafRef\" />" +
 77                    "<Value Type=\"Text\">" + tempButton.CommandName + "</Value></BeginsWith></Where>";
 78                }

 79                else
 80                {
 81                    oView.Query = "";
 82                }

 83                oView.Update();
 84                myWeb.AllowUnsafeUpdates = false;                
 85            }
);
 86        }

 87        catch
 88        {
 89        }

 90        finally
 91        {
 92            mySite = null;
 93            myWeb = null;
 94            this.Response.Redirect(redirectUrl + "&FitlerString=" + tempButton.CommandName, true);    
 95        }
        
 96    }

 97
 98   
 99</script>
100<table class="ms-quicklaunchheader" style="width:500px " >
101<tr>
102<td>&nbsp;&nbsp;&nbsp;
103<asp:LinkButton ID="All" runat="server" CommandName="ALL" OnClick="LinkButton_Click" >All</asp:LinkButton>&nbsp;
104<asp:LinkButton ID="A" runat="server"  CommandName="A" OnClick="LinkButton_Click">A</asp:LinkButton>&nbsp;
105<asp:LinkButton ID="B" runat="server" CommandName="B" OnClick="LinkButton_Click">B</asp:LinkButton>&nbsp;
106<asp:LinkButton ID="C" runat="server" CommandName="C" OnClick="LinkButton_Click">C</asp:LinkButton>&nbsp;
107<asp:LinkButton ID="D" runat="server" CommandName="D" OnClick="LinkButton_Click">D</asp:LinkButton>&nbsp;
108<asp:LinkButton ID="E" runat="server" CommandName="E" OnClick="LinkButton_Click">E</asp:LinkButton>&nbsp;
109<asp:LinkButton ID="F" runat="server" CommandName="F" OnClick="LinkButton_Click">F</asp:LinkButton>&nbsp;
110<asp:LinkButton ID="G" runat="server" CommandName="G" OnClick="LinkButton_Click">G</asp:LinkButton>&nbsp;
111<asp:LinkButton ID="H" runat="server" CommandName="H" OnClick="LinkButton_Click">H</asp:LinkButton>&nbsp;
112<asp:LinkButton ID="I" runat="server" CommandName="I" OnClick="LinkButton_Click">I</asp:LinkButton>&nbsp;
113<asp:LinkButton ID="J" runat="server" CommandName="J" OnClick="LinkButton_Click">J</asp:LinkButton>&nbsp;
114<asp:LinkButton ID="K" runat="server" CommandName="K" OnClick="LinkButton_Click">K</asp:LinkButton>&nbsp;
115<asp:LinkButton ID="L" runat="server" CommandName="L" OnClick="LinkButton_Click">L</asp:LinkButton>&nbsp;
116<asp:LinkButton ID="M" runat="server" CommandName="M" OnClick="LinkButton_Click">M</asp:LinkButton>&nbsp;
117<asp:LinkButton ID="N" runat="server" CommandName="N" OnClick="LinkButton_Click">N</asp:LinkButton>&nbsp;
118<asp:LinkButton ID="O" runat="server" CommandName="O" OnClick="LinkButton_Click">O</asp:LinkButton>&nbsp;
119<asp:LinkButton ID="P" runat="server" CommandName="P" OnClick="LinkButton_Click">P</asp:LinkButton>&nbsp;
120<asp:LinkButton ID="Q" runat="server" CommandName="Q" OnClick="LinkButton_Click">Q</asp:LinkButton>&nbsp;
121<asp:LinkButton ID="R" runat="server" CommandName="R" OnClick="LinkButton_Click">R</asp:LinkButton>&nbsp;
122<asp:LinkButton ID="S" runat="server" CommandName="S" OnClick="LinkButton_Click">S</asp:LinkButton>&nbsp;
123<asp:LinkButton ID="T" runat="server" CommandName="T" OnClick="LinkButton_Click">T</asp:LinkButton>&nbsp;
124<asp:LinkButton ID="U" runat="server" CommandName="U" OnClick="LinkButton_Click">U</asp:LinkButton>&nbsp;
125<asp:LinkButton ID="V" runat="server" CommandName="V" OnClick="LinkButton_Click">V</asp:LinkButton>&nbsp;
126<asp:LinkButton ID="W" runat="server" CommandName="W" OnClick="LinkButton_Click">W</asp:LinkButton>&nbsp;
127<asp:LinkButton ID="X" runat="server" CommandName="X" OnClick="LinkButton_Click">X</asp:LinkButton>&nbsp;
128<asp:LinkButton ID="Y" runat="server" CommandName="Y" OnClick="LinkButton_Click">Y</asp:LinkButton>&nbsp;
129<asp:LinkButton ID="Z" runat="server" CommandName="Z" OnClick="LinkButton_Click">Z</asp:LinkButton>&nbsp;
130</td>
131</tr>
132</table>

 

 

  

如果你不知道如何使用quickpart,请进入这里  

posted on 2008-07-27 11:35  希望(Jack)  阅读(2266)  评论(0编辑  收藏  举报