普通用戶界面
在用戶登錄頁面ST_loginaspx中單擊回首頁超鏈接時將直接轉入到普通用戶界面ST_indexaspx此頁面為普通用戶提供的主要功能有博客列表推薦文章網友回應友情BLOG和個人資料等ST_indexaspx頁面在系統預覽中已經列出(如圖所示)在此主要介紹其後台事件處理頁面ST_indexaspxcs主要代碼如程序所示
程序 ST_indexaspxcs
protected void Page_Load(object sender SystemEventArgs e)
{
//在此處放置用戶代碼以初始化頁面
string ST_dns = ConfigurationSettingsAppSettings[conn];
//最新推薦文章指定的SQL語句
string ST_cmd_sql = select top *
from ST_news where ST_n_iscmd=
order by ST_n_date desc;
//創建數據庫連接
ST_myConn = new OleDbConnection(ST_dns)
//創建OleDbCommand對象對SQL語句進行操作
OleDbDataAdapter ST_classCmd = new OleDbDataAdapter(select
ST_c_idST_c_name from ST_classST_myConn)
OleDbDataAdapter ST_cmdCmd = new
OleDbDataAdapter(ST_cmd_sqlST_myConn)
//創建DataSet的實例
DataSet ST_classds = new DataSet()
//將信息填充到ST_classds
ST_classCmdFill(ST_classds類別列表)
DataSet ST_cmdds = new DataSet()
ST_cmdCmdFill(ST_cmdds推薦文章)
// GridView獲得DataSet的記錄
ClassListDataSource = new DataView(ST_classdsTables[])
//綁定GridView
ClassListDataBind()
CmdListDataSource = new DataView(ST_cmddsTables[])
CmdListDataBind()
NewsList_Bind()
//判斷Cookies是否為空
if (RequestCookies[colors]!=null)
{
string ST_test = RequestCookies[colors]Value;
String[] ST_colorList = ST_testSplit(new char[] { })
ST_bgcolor = ST_colorList[];
ST_tcolor = ST_colorList[];
}
else
{
ST_bgcolor = #FFDE;
ST_tcolor = #efece;
}
PageDataBind()
}
public void NewsList_Bind()
{
string ST_sql;
if (RequestQueryString[c_id]==null)
{
ST_sql = select * from ST_news order by ST_n_date desc;
}
else
{
if (IsSafe(RequestQueryString[c_id])==true)
{
ST_sql = select * from ST_news where ST_c_id=+
RequestQueryString[c_id] + order by ST_n_date desc;
}
else
{
ST_sql=;
ResponseWrite(非法參數)
ResponseEnd()
}
}
OleDbDataAdapter ST_myCmd = new
OleDbDataAdapter(ST_sqlST_myConn)
DataSet ST_ds = new DataSet()
ST_myCmdFill(ST_ds新聞列表)
NewsListDataSource = new DataView(ST_dsTables[])
NewsListDataBind()
}
【代碼說明】頁面進行初始化時代碼第行調用NewsList_Bind()方法從數據庫中獲取信息填充頁面代碼第行用到了IsSafe()方法這是當前頁面中自定義的方法用來驗證參數值是否都是數字因為如果是ID則不能有字符
說明ResponseEnd()表示結束輸出
返回目錄ASPNET項目開發指南
編輯推薦
ASPNET MVC 框架揭秘
ASPNET開發寶典
ASP NET開發培訓視頻教程
From:http://tw.wingwit.com/Article/program/net/201311/15878.html