页面根据不同Url显示不同Title以及不同的Mete
2006-07-24 17:13:03 来源:WEB开发网数据库采用SQL Server 2005 ExPRess Edition, 数据库构造就不说了。
SQL语句: SELECT title, keyWords, description FROM PageInfo WHERE (url= @url)SqlDataSource,名字为sds
具体的代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Header_cs : System.Web.UI.MasterPage {
protected void Page_Load(object sender, EventArgs e) {
sds.SelectParameters.Add("url",
Request.AppRelativeCurrentExecutionFilePath);
IDataReader reader =
(IDataReader)sds.Select(new DataSourceSelectArguments());
if (reader.Read()) {
Page.Header.Title = reader.GetString(0);
HtmlMeta meta1 = new HtmlMeta();
HtmlMeta meta2 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = reader.GetString(1);
meta2.Name = "description";
meta2.Content = reader.GetString(2);
Page.Header.Controls.Add(meta1);
Page.Header.Controls.Add(meta2);
}
}
}
更多精彩
赞助商链接