news.ascx.cs
来自「ASP.NET2.0(C#篇)经典教程的源码...本源码很好的实现了购物车...」· CS 代码 · 共 43 行
CS
43 行
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
partial class NewsControl : System.Web.UI.UserControl
{
private int _itemsToShow = 5;
public int ItemsToShow
{
get {return _itemsToShow;}
set {_itemsToShow = value;}
}
private void Page_PreRender( object sender, System.EventArgs e)
{
// modify the select statement so that only the required number of items are shown, and
// then only those that are older than today's date. This allows the database to be pre-filled
// with news items, and they'll only show when that date arrives.
string sel = string .Format("SELECT Top {0} * FROM [News] WHERE DateToShow <= GETDATE() ORDER BY DateToShow DESC", _itemsToShow);
SqlDataSource1.SelectCommand = sel;
}
protected void NewsItem_DataBound( object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
DataRowView row;
Image img;
// if there's no picture associated with this news item, then hide the image
// this stops the //missing image// icon being shown
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
row = (DataRowView)e.Item.DataItem;
if (row["PictureUrl"].ToString().Trim() == "")
{
img = (Image)e.Item.FindControl("NewsImage");
img.Visible = false;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?