程序 ST_RoomsManModuleascxcs
…
protected void GridView_Delete(Object sender
GridViewDeleteEventArgs E)
{
//從文件WebConfig中讀取連接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn = new SqlConnection (ST_sqldb)
ST_ConnOpen ()
//創建ST_mycommand對象調用存儲過程
SqlCommand ST_mycommand = new SqlCommand (ST_DeleteRoomST_Conn)
ST_mycommandCommandType=CommandTypeStoredProcedure;
ST_mycommandParameters Add (@RoomIdSqlDbTypeInt )
//從dg_RoomsList中獲取UserId值
ST_mycommandParameters[@RoomId]Value =
dg_RoomsListDataKeys[ERowIndex]ValueToString()
ST_mycommandExecuteNonQuery ()
dg_RoomsListEditIndex =;
//更新dg_RoomsList
Show_RoomsList()
}
protected void GridView_Page(Object sender GridViewPageEventArgs E)
{
dg_RoomsListPageIndex =ENewPageIndex ;
Show_RoomsList()
}
private void search_Click(object sender SystemEventArgs e)
{
//從文件WebConfig中讀取連接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn = new SqlConnection (ST_sqldb)
//創建SqlDataAdapter對象調用存儲過程ST_ShowRoomsInfo
SqlDataAdapter ST_myadapter = new SqlDataAdapter
(ST_ShowRoomByIdST_Conn)
ST_myadapterSelectCommandCommandType
=CommandTypeStoredProcedure;
ST_myadapterSelectCommandParameters Add
(@RoomIdSqlDbTypeInt)
ST_myadapterSelectCommandParameters [@RoomId]Value
=RoomIdTextBoxTextTrim()
//創建並填充DataSet
DataSet ds = new DataSet ()
ST_myadapterFill (ds)
dg_RoomsListDataSource =ds;
dg_RoomsListDataBind ()
ST_ConnClose ()
}
private void ShowAll_Click(object sender SystemEventArgs e)
{
Show_RoomsList()
}
…
【代碼說明】代碼第行很關鍵用來獲取被刪除行的IDERowIndex用來獲取用戶選擇的是第幾行DataKeys[ERowIndex]Value表示當前行中主鍵的值代碼第行說明獲取數據使用的是存儲過程代碼第~行將數據綁定到dg_RoomsList
返回目錄ASPNET項目開發指南
編輯推薦
ASPNET MVC 框架揭秘
ASPNET開發寶典
ASP NET開發培訓視頻教程
[] []
From:http://tw.wingwit.com/Article/program/net/201311/15978.html