📄 news.ascx.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -