熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET項目開發指南:房間信息的修改和刪除(2)[1]

2022-06-13   來源: .NET編程 

    房間信息的修改和刪除(

  ST_RoomEditModuleascxcs的主要代碼及其解釋

  後台代碼主要實現數據的綁定和顯示如程序所示

  程序  ST_RoomEditModuleascxcs

    public partial class ST_RoomEditModule : ST_ModuleBase

    {

        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 dr=ST_commandExecuteReader ()

                while(drRead ())

                {

                    ListItem li=new

    ListItem(dr[ST_Name]ToString()dr[ST_RCategoryId]ToString())

                    RCategoryNameListItemsAdd (li)

                }

                ST_ConnClose ()

  

                //顯示房間信息

                RoomIdLabelText=RequestQueryString [RoomId]

                    ToString ()

                //連接ST_GinShopManage數據庫

                SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

                ST_ConnOpen ()

                //利用Command對象調用存儲過程

                SqlCommand ST_mycommand=new SqlCommand

                    (ST_ShowRoomByIdST_Conn

                //將命令類型設置為存儲類型

                ST_mycommandCommandType =CommandTypeStoredProcedure ;

                ST_mycommandParameters Add (@RoomIdSqlDbTypeInt)

                ST_mycommandParameters [@RoomID]Value =

                    intParse(RoomIdLabelText)

                SqlDataReader dr=ST_mycommandExecuteReader ()

                if(drRead ())

                {

                    //設置DropDownList的默認值

                    RCategoryNameListItemsFindByText

                    (dr[ST_Name]ToString())Selected=true;

                    RPositionTextBoxText

                        =dr[ST_RPosition]ToString()

                    DescriptionTextBoxText

                        =dr[ST_Description]ToString ()

                }

                //關閉ST_Conn

                ST_ConnClose()

            }

    }

    …

  【代碼說明】當頁面被首次加載時將讀取ST_RoomCategory表中的ST_RCategoryId和ST_Name列將讀出的ST_RCategoryId作為ListItem類型的li的Value屬性將ST_Name作為li的Text屬性然後再添加到RCategoryNameListItems的集合中這些都是給頁面中的DropDownList添加Item

  NotNullValidate事件在頁面提交時將驗證是否選擇了房間類型如果沒有則停止提交Submit_Click是在管理員單擊了修改信息按鈕後觸發的事件在這裡獲取管理員修改的信息然後再將這些信息更新到數據庫中其主要代碼如程序所示

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15974.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.