温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:
SpaceBuiderV10Source/BasicWebControls/Channel/Search/NewsSearchResults.cs[5K,2009-6-12 11:55:07],打开代码结构图
SpaceBuiderV10Source/BasicWebControls/Channel/Search/NewsSearchResults.cs[5K,2009-6-12 11:55:07],打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
using System; 7
using System.Collections.Generic; 8
using System.Text; 9
using SpaceBuilder.Controls.BaseClasses; 10
using SpaceBuilder.Controls.Utils; 11
using System.Web.UI.HtmlControls; 12
using System.Web.UI.WebControls; 13
using SpaceBuilder.Posts.Components; 14
using TunyNet.Data.Utils; 15
using SpaceBuilder.Posts.Providers; 16
using TunyNet.Utils; 17
using SpaceBuilder.Utils; 18
using SpaceBuilder.Components; 19
20
namespace SpaceBuilder.Search.Controls 21
{ 22
public class NewsSearchResults : TemplatedWebControl 23
{ 24
25
protected override void OnInit(EventArgs e) 26
{ 27
if (SkinName == null) 28
ExternalSkinFileName = "Searchs/Skin-NewsSearchResults.ascx"; 29
else 30
ExternalSkinFileName = SkinName; 31
base.OnInit(e); 32
} 33
34
Child Controls 45
46
protected override void AttachChildControls() 47
{ 48
statusMessage = FindControl("StatusMessage") as StatusMessage; 49
noResultsDiv = FindControl("NoResultsDiv") as HtmlControl; 50
listPostsDiv = FindControl("ListPostsDiv") as HtmlControl; 51
searchHint = FindControl("SearchHint") as Literal; 52
53
postsRepeater = FindControl("PostsRepeater") as Repeater; 54
if(postsRepeater!=null) 55
postsRepeater.ItemDataBound += new RepeaterItemEventHandler(postsRepeater_ItemDataBound); 56
pager = FindControl("Pager") as Pager; 57
} 58
59
protected override void OnLoad(EventArgs e) 60
{ 61
base.OnLoad(e); 62
EnsureChildControls(); 63
if (!Page.IsPostBack) 64
BindData(); 65
} 66
67
private void BindData() 68
{ 69
PostFullTextQuery query = new PostFullTextQuery(); 70
query.ConvertFromQueryString(); 71
if (query.IsValid()) 72
{ 73
query.PageSize = 10; 74
query.PageIndex = pager.PageIndex; 75
76
SearchResultDataSet<PostSearchItem> pds = PostSearchProvider.Instance().Search(query); 77
postsRepeater.DataSource = pds.Records; 78
postsRepeater.DataBind(); 79
80
if (pds.TotalRecords > 0) 81
{ 82
searchHint.Text = "约有 <span class='stress'>" + pds.TotalRecords + " </span>个资讯满足搜索条件,搜索用时 " + pds.SearchDuration + " 秒"; 83
84
pager.TotalRecords = pds.TotalRecords; 85
pager.PageSize = query.PageSize; 86
} 87
else 88
{ 89
noResultsDiv.Visible = true; 90
listPostsDiv.Visible = false; 91
} 92
} 93
else 94
{ 95
listPostsDiv.Visible = false; 96
statusMessage.Visible = true; 97
statusMessage.MessageType = StatusMessageType.Error; 98
statusMessage.Text = "请填写您的搜索条件,再进行搜索"; 99
} 100
} 101
102
void postsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 103
{ 104
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 105
{ 106
PostSearchItem item = e.Item.DataItem as PostSearchItem; 107
if (item != null) 108
{ 109
HyperLink subject = e.Item.FindControl("Subject") as HyperLink; 110
if (subject != null) 111
{ 112
subject.Text = StringUtils.Trim(item.Subject, this.displayItemNameLength); 113
subject.NavigateUrl = Globals.FullPathForMainSite(item.PostUrl); 114
subject.ToolTip = item.Subject; 115
} 116
117
Literal body = e.Item.FindControl("Body") as Literal; 118
if (body != null) 119
body.Text = StringUtils.Trim(item.Body,this.displayItemBodyLength); 120
121
Literal lastUpdatedDate = e.Item.FindControl("LastUpdatedDate") as Literal; 122
if (lastUpdatedDate != null) 123
lastUpdatedDate.Text = Formatter.FormatDate(item.LastUpdatedDate); 124
} 125
} 126
} 127
128
属性 145
146
} 147
} 148






}
}