protected void AddButton_Click(object sender, EventArgs e) { if ((!string.IsNullOrEmpty(TitleTextBox.Text)) && (!string.IsNullOrEmpty(TextBox.Text))) { if (AddButton.Text.Equals(GetLocalResourceObject("AddButton").ToString())) { Notice notice = new Notice(); notice.Title = TitleTextBox.Text; notice.Text = TextBox.Text; NewsDB.Insert(notice); NewsDB.SortByDate(); TitleTextBox.Text = null; TextBox.Text = null; XmlDataSource1.DataBind(); NewsRepeater.DataBind(); Response.Redirect("News.aspx"); } else { Notice notice = NewsDB.Get(Int32.Parse(Session["tempId"].ToString())); notice.Title = TitleTextBox.Text; notice.Text = TextBox.Text; NewsDB.Update(notice); TitleTextBox.Text = null; TextBox.Text = null; AddButton.Text = GetLocalResourceObject("AddButton").ToString(); XmlDataSource1.DataBind(); NewsRepeater.DataBind(); Response.Redirect("News.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { List <NewsModel> list = bll.ShowNews(); NewsRepeater.DataSource = list; NewsRepeater.DataBind(); }
private void Bind() { PagedDataSource ps = new PagedDataSource(); ps.DataSource = bll.ShowAllNews(); ps.AllowPaging = true; ps.PageSize = 20; lbPage.Text = ps.PageCount.ToString(); ps.CurrentPageIndex = currentPage; FirstPage.Enabled = true; PriorPage.Enabled = true; NextPage.Enabled = true; LastPage.Enabled = true; if (lbCurrentPage.Text == "1") { FirstPage.Enabled = false; PriorPage.Enabled = false; } if (lbCurrentPage.Text == ps.PageCount.ToString()) { NextPage.Enabled = false; LastPage.Enabled = false; } NewsRepeater.DataSource = ps; NewsRepeater.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { IList <Tag> list = TagService.GetInstance().GetTag(null); TagRepeater.DataSource = list; TagRepeater.DataBind(); News news = new News(); news.Title = "2"; IList <News> listNews = NewsService.GetInstance().GetNews(news); NewsRepeater.DataSource = listNews; NewsRepeater.DataBind(); }
/// <summary> /// 分页读取技术支持文章,默认12条分页,按 是否置顶 和 时间 排序,读取前120条 /// </summary> protected void RepeaterPaging() { string strConnection = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString; OleDbConnection objConnection = new OleDbConnection(strConnection); objConnection.Open(); string strSQL = "SELECT TOP 120 * FROM JSZCTable WHERE articleDelete=false ORDER BY isTop, articleTime DESC "; OleDbDataAdapter daForRepeator = new OleDbDataAdapter(strSQL, objConnection); DataSet dsForRepeator = new DataSet(); daForRepeator.Fill(dsForRepeator, "article"); PagedDataSource pds = new PagedDataSource(); pds.DataSource = dsForRepeator.Tables["article"].DefaultView; pds.AllowPaging = true; pds.PageSize = 12; pds.CurrentPageIndex = Convert.ToInt32(this.CurrentPageLabel.Text) - 1; TotalPageLabel.Text = pds.PageCount.ToString(); CurrentPageLabel.Text = (pds.CurrentPageIndex + 1).ToString(); FirstLinkButton.Enabled = true; LastLinkButton.Enabled = true; NextLinkButton.Enabled = true; PreLinkButton.Enabled = true; DropDownListPageNum.Items.Clear(); for (int i = 1; i < pds.PageCount + 1; ++i) { ListItem li = new ListItem(i.ToString(), i.ToString()); DropDownListPageNum.Items.Add(li); } DropDownListPageNum.SelectedValue = CurrentPageLabel.Text; if (pds.CurrentPageIndex < 1) { FirstLinkButton.Enabled = false; PreLinkButton.Enabled = false; } if (pds.CurrentPageIndex == pds.PageCount - 1) { LastLinkButton.Enabled = false; NextLinkButton.Enabled = false; } NewsRepeater.DataSource = pds; NewsRepeater.DataBind(); objConnection.Close(); }
private void newsDate() { string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //連接資料庫 SqlConnection Conn = new SqlConnection(ConnectionString); Conn.Open(); //Cmd執行SQL語法 SqlCommand Cmd = new SqlCommand("SELECT TOP 3 id, CONVERT(char(10), NewsDate, 111)NewsDate, NewsTitle, Sticky, PrePhotoName, Introduction FROM News ORDER BY Sticky DESC, id DESC", Conn); SqlDataReader Reader = Cmd.ExecuteReader(); NewsRepeater.DataSource = Reader; NewsRepeater.DataBind(); Reader.Close(); Cmd.Cancel(); Conn.Close(); Conn.Dispose(); }
protected void Page_Load(object sender, EventArgs e) { XmlDataSource1.DataBind(); NewsRepeater.DataBind(); if (Request["Id"] != null) { Notice notice = NewsDB.Get(Convert.ToInt32(Request["Id"])); if (notice != null) { DeleteButton.Visible = true; TitleTextBox.Text = notice.Title; TextBox.Text = notice.Text; AddButton.Text = GetLocalResourceObject("EditButton").ToString(); Session["tempId"] = notice.Id; } } else { DeleteButton.Visible = false; } }
protected void DeleteButton_Click(object sender, EventArgs e) { if (DeleteButton.BackColor == System.Drawing.Color.Green) { Notice notice = new Notice(); notice.Id = Int32.Parse(Session["tempId"].ToString()); NewsDB.Delete(notice); DeleteButton.BackColor = System.Drawing.Color.Red; DeleteButton.Text = GetLocalResourceObject("DeleteButton").ToString(); AddButton.Text = GetLocalResourceObject("AddButton").ToString(); DeleteButton.Visible = false; TitleTextBox.Text = null; TextBox.Text = null; XmlDataSource1.DataBind(); NewsRepeater.DataBind(); Response.Redirect("News.aspx"); } else { DeleteButton.Text = GetLocalResourceObject("ReallyButton").ToString(); DeleteButton.BackColor = System.Drawing.Color.Green; } }
protected void Page_Load(object sender, EventArgs e) { DataTable dataTable = new DataTable(); if (Cache[CacheKeys.FrontNews] != null) { dataTable = (DataTable)Cache[CacheKeys.FrontNews]; } else { string connString = ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString; SqlConnection sqlConn = new SqlConnection(connString); sqlConn.Open(); const string sql = "SELECT TOP 3 yaf_topic.topicid, yaf_topic.topic, yaf_message.message, yaf_message.posted, " + " (" + " SELECT count(*) FROM yaf_message WHERE topicid=yaf_topic.topicid "+ " )-1 AS replies "+ "FROM yaf_topic, yaf_message " + "WHERE " + " yaf_topic.priority=2 AND " + " yaf_topic.topicid=yaf_message.topicid AND " + " yaf_message.replyto IS NULL AND " + " yaf_Message.IsDeleted = 0" + "ORDER BY posted DESC "; SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConn); dataAdapter.Fill(dataTable); sqlConn.Close(); Cache.Insert(CacheKeys.FrontNews, dataTable, null, DateTime.Now.AddMinutes(30), System.Web.Caching.Cache.NoSlidingExpiration); } NewsRepeater.DataSource = dataTable; NewsRepeater.DataBind(); }
public void loadData() { NewsRepeater.DataSource = FoodN.DAO.IntroNews.get6TopRecentNews(); NewsRepeater.DataBind(); }
protected void BindData() { int howManyPages = 1; DataTable news = SiteFrontend.FrontNews.GetNewsIDs(int.Parse(_page), _newsPerPage, out howManyPages); NewsRepeater.DataSource = news; NewsRepeater.DataBind(); if (_newsID == 0) { if (news.Rows.Count > 0) { DataRow row = news.Rows[0]; _newsID = int.Parse(row["NewsID"].ToString()); } } if (_newsID > 0) { DataTable n = FrontNews.GetNews(_newsID); if (n.Rows.Count > 0) { DataRow r = n.Rows[0]; lblNewsTitle.Text = r["NewsTitle"].ToString(); lblNewsDate.Text = String.Format("{0:M/d/yyyy}", DateTime.Parse(r["Modified"].ToString())); NewsContentDiv.InnerHtml = r["NewsDesc"].ToString(); } } if (howManyPages > 1) { int currentPage = Int32.Parse(_page); pagingLabel.Visible = true; previousLink.Visible = true; nextLink.Visible = true; firstLink.Visible = true; lastLink.Visible = true; pagingLabel.Text = _page + " / " + howManyPages.ToString(); // create previous link if (currentPage == 1) { previousLink.Enabled = false; firstLink.Enabled = false; } else { NameValueCollection query = Request.QueryString; string paramName, newQueryString = "?"; for (int i = 0; i < query.Count; i++) { if (query.AllKeys[i] != null) { if ((paramName = query.AllKeys[i].ToString()).ToUpper() != "PAGE") { newQueryString += paramName + "=" + query[i] + "&"; } } } previousLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=" + (currentPage - 1).ToString(); firstLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=1"; } //create next link if (currentPage == howManyPages) { nextLink.Enabled = false; lastLink.Enabled = false; } else { NameValueCollection query = Request.QueryString; string paramName, newQueryString = "?"; for (int i = 0; i < query.Count; i++) { if (query.AllKeys[i] != null) { if ((paramName = query.AllKeys[i].ToString()).ToUpper() != "PAGE") { newQueryString += paramName + "=" + query[i] + "&"; } } } nextLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=" + (currentPage + 1).ToString(); lastLink.NavigateUrl = Request.Url.AbsolutePath + newQueryString + "Page=" + howManyPages.ToString(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["action"] == "quitadmin") { if (Session["AdminName"] != null) { Session["AdminName"] = null; } } (Page.Master.FindControl("ProductsClassTreeView") as TreeView).ExpandDepth = 0; string strConnection = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString; OleDbConnection objConnection = new OleDbConnection(strConnection); objConnection.Open(); using (objConnection) { #region 读取公司信息表 string _sql = "SELECT TOP 1 LXFS,GSJJ,IsShowBannerImage,IsScrollStarProducts,ScrollSpeed,ScrollPicNum FROM XXTable"; OleDbDataAdapter da = new OleDbDataAdapter(_sql, objConnection); DataSet ds = new DataSet(); //填充DataSet da.Fill(ds, "nb"); DataTable _dt = ds.Tables["nb"]; ContactInf.Text = _dt.Rows[0]["LXFS"].ToString(); AboutUSLiteral.Text = _dt.Rows[0]["GSJJ"].ToString(); //下面读取设置信息 IsShowBannerImage = bool.Parse(_dt.Rows[0]["IsShowBannerImage"].ToString()); IsScrollStarProducts = Convert.ToBoolean(_dt.Rows[0]["IsScrollStarProducts"]); ScrollSpeed = Convert.ToInt32(_dt.Rows[0]["ScrollSpeed"]); int ScrollPicNum = Convert.ToInt32(_dt.Rows[0]["ScrollPicNum"]); #endregion #region 读取最新的4条新闻 _sql = "SELECT TOP 4 * FROM XWTable WHERE newsDelete=false ORDER BY isTop, newsTime DESC"; OleDbDataAdapter daForRepeator = new OleDbDataAdapter(_sql, objConnection); DataTable dtForRepeator = new DataTable(); daForRepeator.Fill(dtForRepeator); NewsRepeater.DataSource = dtForRepeator; NewsRepeater.DataBind(); #endregion #region 读取明星产品 if (IsScrollStarProducts) { _sql = string.Format("SELECT TOP {0} * FROM ProductsShowTable WHERE IsDel=false ORDER BY PosIndex DESC", ScrollPicNum); } else { _sql = "SELECT TOP 4 * FROM ProductsShowTable WHERE IsDel=false ORDER BY PosIndex DESC"; } daForRepeator = new OleDbDataAdapter(_sql, objConnection); DataTable dtForStarProRepeator = new DataTable(); daForRepeator.Fill(dtForStarProRepeator); StarProductsRepeater.DataSource = dtForStarProRepeator; StarProductsRepeater.DataBind(); #endregion #region 读取BannerImage信息 //读取页面BannerImg的信息 _sql = "SELECT TOP 6 * FROM BannerImageTable WHERE IsDel=false ORDER BY PosIndex DESC"; daForRepeator = new OleDbDataAdapter(_sql, objConnection); dtForStarProRepeator = new DataTable(); daForRepeator.Fill(dtForStarProRepeator); foreach (DataRow item in dtForStarProRepeator.Rows) { BannerImageInfor newImageInfor = new BannerImageInfor(); newImageInfor.ImageUrl = item["imgUrl"].ToString(); newImageInfor.ImageLink = item["imgLink"].ToString(); newImageInfor.ImageText = item["imgText"].ToString(); BannerImageInfors.Add(newImageInfor); } #endregion } } }