當管理員單擊DataList中的房間號按鈕時將觸發Button_Click事件以房間號為條件從數據庫中讀取該房間的具體信息再綁定到rp_RoomDetails該事件的部分代碼如程序所示
程序 ST_RBusiManModuleascxcs
…
protected void Button_Click(object sender EventArgs e)
{
int ST_RoomId = intParse(((Button)sender)Text)
//從文件WebConfig中讀取連接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn = new SqlConnection(ST_sqldb)
//創建SqlDataAdapter對象調用存儲過程ST_ShowRoomsInfo
SqlDataAdapter ST_myadapter = new
SqlDataAdapter(ST_GetRoomDetails ST_Conn)
ST_myadapterSelectCommandCommandType =
CommandTypeStoredProcedure;
ST_myadapterSelectCommandParametersAdd(@RoomId
SqlDbTypeInt)
ST_myadapterSelectCommandParameters[@RoomID]Value =
ST_RoomId;
//創建並填充DataSet
DataSet ST_ds = new DataSet()
ST_myadapterFill(ST_ds Rooms)
DataRow dr = ST_dsTables[]Rows[];
rp_RoomDetailsDataSource = ST_ds;
rp_RoomDetailsDataBind()
//根據房間狀態確定酒店業務
if (dr[ST_Status]ToString() == )
{
//如果房間被訂預訂業務不可用
((HyperLink)rp_RoomDetailsItems[]
FindControl(OrderLink))Enabled = false;
}
else if (dr[ST_Status]ToString() == )
{
//如果房間未訂退房業務不可用
((HyperLink)rp_RoomDetailsItems[]
FindControl(CheckOutLink))Enabled = false;
}
ST_ConnClose()
}
【代碼說明】代碼第行實現了獲取房間號代碼第~行利用存儲過程ST_GetRoomDetails查詢數據然後在代碼第~行綁定並顯示查詢結果代碼第~行判斷查詢結果中的房間狀態然後設置預訂和退房業務
返回目錄ASPNET項目開發指南
編輯推薦
ASPNET MVC 框架揭秘
ASPNET開發寶典
ASP NET開發培訓視頻教程
[] []
From:http://tw.wingwit.com/Article/program/net/201311/15967.html