protected void Page_Load(object sender, EventArgs e) { hotwordsRepeater.DataSource = new KeywordDao().GetHotWords(); hotwordsRepeater.DataBind(); kw = Request["kw"]; if (string.IsNullOrWhiteSpace(kw)) { return; } //处理:将用户的搜索记录加入数据库,方便统计热词 SerachKeyword model = new SerachKeyword(); model.Keyword = kw; model.SearchDateTime = DateTime.Now; model.ClinetAddress = Request.UserHostAddress; new KeywordDao().Add(model); //分页控件 MyPage pager = new MyPage(); pager.TryParseCurrentPageIndex(Request["pagenum"]); //超链接href属性 pager.UrlFormat = "Search.aspx?pagenum={n}&kw=" + Server.UrlEncode(kw); int startRowIndex = (pager.CurrentPageIndex - 1) * pager.PageSize; int totalCount = -1; List <SearchResult> list = DoSearch(startRowIndex, pager.PageSize, out totalCount); pager.TotalCount = totalCount; RenderToHTML = pager.RenderToHTML(); dataRepeater.DataSource = list; dataRepeater.DataBind(); }
/// <summary> /// 添加关键字 /// </summary> /// <param name="searchKeyword"></param> /// <returns></returns> public int Add (SerachKeyword searchKeyword) { string sql = "INSERT INTO Keywords (SearchDateTime, KeyWord, ClientAddress) output inserted.KeywordID VALUES (@SearchDateTime, @KeyWord, @ClientAddress)"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@SearchDateTime", searchKeyword.SearchDateTime), new SqlParameter("@KeyWord", searchKeyword.Keyword), new SqlParameter("@ClientAddress", searchKeyword.ClinetAddress), }; return(SqlHelper.ExecuteNonQuery(sql, para)); }