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