房間經營管理頁面的搭建()
ST_RBusiManModuleascxcs的主要代碼及其解釋
Page_Load()事件用來獲取綁定數據到下拉列表框然後調用Show_RoomsList()方法顯示房間信息如程序所示
程序 ST_RBusiManModuleascxcs
public partial class ST_RBussiModule : ST_ModuleBase
{
protected string Status;
private void Page_Load(object sender SystemEventArgs e)
{
if(!IsPostBack)
{
//綁定按房間類型下拉列表框
//從文件WebConfig中讀取連接字符串
string ST_sqldb=
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb)
ST_ConnOpen ()
//定義SQL語句
string ST_mysql=select ST_RCategoryIdST_Name from
ST_RoomCategory ;
SqlCommand ST_command=new SqlCommand(ST_mysqlST_Conn)
SqlDataReader ST_dr=ST_commandExecuteReader()
while(ST_drRead ())
{
ListItem li=new ListItem(ST_dr[ST_Name]
ToString()ST_dr[ST_RCategoryId]ToString())
RCategoryNameListItemsAdd (li)
}
ST_ConnClose ()
//dl_RoomsList顯示房間信息
Show_RoomsList()
}
}
//dl_RoomsList顯示房間信息
protected void Show_RoomsList()
{
if(dl_RoomsListSelectedIndex>){
dl_RoomsListSelectedIndex=;
}
//從文件WebConfig中讀取連接字符串
string ST_sqldb=
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb)
//創建SqlDataAdapter對象調用存儲過程ST_ShowRoomsInfo
SqlDataAdapter ST_myadapter=new SqlDataAdapter
(ST_ShowRoomsInfoST_Conn)
//創建並填充DataSet
DataSet ST_ds = new DataSet ()
ST_myadapterFill (ST_dsRoomsList)
dl_RoomsListDataSource =ST_ds;
dl_RoomsListDataBind ()
//根據房間狀態確定dl_RoomsList的Status顯示
for(int i=;i<dl_RoomsListItemsCount;i++)
{
DataRow dr=ST_dsTables[]Rows[i];
if(dr[ST_Status]ToString()==)
{
((Label)dl_RoomsListItems[i]
FindControl(StatusLabel))Text=否;
Status=否;
}
else if(dr[ST_Status]ToString()==)
{
((Label)dl_RoomsListItems[i]
FindControl(StatusLabel))Text=有;
Status=是;
}
}
ST_ConnClose ()
}
…
【代碼說明】當頁面被首次加載時將讀取房間類型並將類型賦值給DropDownList然後再調用方法Show_RoomsList()在此方法中首先從數據庫中讀出有關房間的信息然後再綁定到dl_RoomsList因為頁面的客戶端代碼中使用了<%=Status%>變量所以代碼第行定義了這個變量並在代碼第~行為這個變量賦值
返回目錄ASPNET項目開發指南
編輯推薦
ASPNET MVC 框架揭秘
ASPNET開發寶典
ASP NET開發培訓視頻教程
From:http://tw.wingwit.com/Article/program/net/201311/15969.html