Asp.net源码专业站
首页->博客空间->SpaceBuilder v1.1源代码>>BasicWebControls/Channel/Search/FileSearchResults.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
当前文件:文件类型 SpaceBuider11/BasicWebControls/Channel/Search/FileSearchResults.cs[6K,2009-6-12 11:54:32]打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.Collections.Generic; 9using System.Text; 10using SpaceBuilder.Controls.BaseClasses; 11using SpaceBuilder.Components; 12using SpaceBuilder.Controls.Utils; 13using System.Web.UI.HtmlControls; 14using System.Web.UI.WebControls; 15using SpaceBuilder.Posts.Components; 16using TunyNet.Data.Utils; 17using SpaceBuilder.Posts.Providers; 18using TunyNet.Utils; 19using SpaceBuilder.Utils; 20 21namespace SpaceBuilder.Search.Controls 22{ 23 /// <summary> 24 /// 显示文件搜索结果 25 /// </summary> 26 public class FileSearchResults : TemplatedWebControl 27 { 28 SBContext wlContext; 29 30 protected override void OnInit(EventArgs e) 31 { 32 if (SkinName == null) 33 ExternalSkinFileName = "Searchs/Skin-FileSearchResults.ascx"; 34 else 35 ExternalSkinFileName = SkinName; 36 37 wlContext = SBContext.Current; 38 base.OnInit(e); 39 } 40 41 protected override void OnLoad(EventArgs e) 42 { 43 base.OnLoad(e); 44 EnsureChildControls(); 45 if (!Page.IsPostBack) 46 Bind(); 47 } 48 49 Child Controls 73 74 /// <summary> 75 /// 附加子控件 76 /// </summary> 77 protected override void AttachChildControls() 78 { 79 statusMessage = FindControl("StatusMessage") as StatusMessage; 80 81 noResultsDiv = FindControl("NoResultsDiv") as HtmlControl; 82 listPostsDiv = FindControl("ListPostsDiv") as HtmlControl; 83 searchHint = FindControl("SearchHint") as Literal; 84 postsRepeater = FindControl("PostsRepeater") as Repeater; 85 pager = FindControl("Pager") as Pager; 86 87 if (postsRepeater != null) 88 postsRepeater.ItemDataBound += new RepeaterItemEventHandler(PostsRepeater_ItemDataBound); 89 } 90 91 void Bind() 92 { 93 PostFullTextQuery query = new PostFullTextQuery(); 94 query.ConvertFromQueryString(); 95 if (query.IsValid()) 96 { 97 query.PageSize = 10; 98 query.PageIndex = pager.PageIndex; 99 100 SearchResultDataSet<PostSearchItem> pds = PostSearchProvider.Instance().Search(query); 101 postsRepeater.DataSource = pds.Records; 102 postsRepeater.DataBind(); 103 104 if (pds.TotalRecords > 0) 105 { 106 searchHint.Text = "约有 <span class='stress'>" + pds.TotalRecords + " </span>个文件满足搜索条件,搜索用时 " + pds.SearchDuration + ""; 107 108 pager.TotalRecords = pds.TotalRecords; 109 pager.PageSize = query.PageSize; 110 } 111 else 112 { 113 noResultsDiv.Visible = true; 114 listPostsDiv.Visible = false; 115 } 116 117 //if (query.SectionID > 0) 118 //{ 119 // Weblog blog = Weblogs.GetWeblog(query.SectionID); 120 // if (blog != null && searchFromSingleBlogBlock != null) 121 // { 122 // searchFromSingleBlogBlock.Visible = true; 123 // searchFromSingleBlogBlock.Attributes["class"] = "commonTitle"; 124 // searchFromSingleBlogBlock.InnerHtml = string.Format("从 (<a href=\"{0}\">{1}</a>) 的搜索结果:", UserUrls.Instance().BlogHome(blog.ApplicationKey), blog.SectionName); 125 // } 126 //} 127 128 } 129 else 130 { 131 listPostsDiv.Visible = false; 132 statusMessage.Visible = true; 133 statusMessage.MessageType = StatusMessageType.Error; 134 statusMessage.Text = "请填写您的搜索条件,再进行搜索"; 135 } 136 } 137 138 private void PostsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 139 { 140 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 141 { 142 PostSearchItem item = e.Item.DataItem as PostSearchItem; 143 if (item != null) 144 { 145 HyperLink subject = e.Item.FindControl("Subject") as HyperLink; 146 if (subject != null) 147 { 148 subject.Text = item.Subject; 149 if (!ValueHelper.IsNullOrEmpty(item.PostUrl)) 150 { 151 subject.NavigateUrl = Globals.FullPathForMainSite(item.PostUrl); 152 subject.Attributes["target"] = "_blank"; 153 } 154 } 155 156 Literal body = e.Item.FindControl("Body") as Literal; 157 if (body != null) 158 body.Text = item.Body; 159 160 HyperLink author = e.Item.FindControl("Author") as HyperLink; 161 if (author != null) 162 { 163 author.Text = item.Author; 164 if (!ValueHelper.IsNullOrEmpty(item.UserProfileUrl)) 165 { 166 author.NavigateUrl = Globals.FullPathForMainSite(item.UserProfileUrl); 167 author.Attributes["target"] = "_blank"; 168 } 169 } 170 171 Literal lastUpdatedDate = e.Item.FindControl("LastUpdatedDate") as Literal; 172 if (lastUpdatedDate != null) 173 lastUpdatedDate.Text = Formatter.FormatDate(item.LastUpdatedDate); 174 175 Literal tags = e.Item.FindControl("Tags") as Literal; 176 if (tags != null && item.Tags != null) 177 { 178 for (int i = 0; i < item.Tags.Length; i++) 179 { 180 tags.Text += string.Format("<a href='{0}' target='_blank'>{1}</a> ", Globals.FullPathForMainSite(ChannelUrls.Instance().ListWebLogPostsByTag(item.Tags[i])), item.Tags[i]); 181 } 182 } 183 } 184 } 185 } 186 187 } 188} 189
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.1源代码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146