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