<script runat="server"> SqlConnection objConn = new SqlConnection(); SqlCommand objCmd = new SqlCommand(); SqlDataAdapter dtAdapter = new SqlDataAdapter(); DataTable dt = new DataTable(); String strConnString, strSQL; void Page_Load(object sender,EventArgs e) { if (Convert.ToString(Session["strUser"]) == "") { Response.Redirect("index.aspx"); Response.End(); } if(!Page.IsPostBack) { BindData(); } } void BindData() { String strSQL; strConnString = "Server=localhost;UID=sa;PASSWORD=12345;database=mydatabase"; objConn = new SqlConnection(strConnString); objConn.Open(); ; strSQL = "SELECT * FROM AddRoom"; objCmd = new SqlCommand(strSQL, objConn); objCmd.Connection = objConn; objCmd.CommandText = strSQL; objCmd.CommandType = CommandType.Text; dtAdapter.SelectCommand = objCmd; dtAdapter.Fill(dt); myGridView.DataSource = dt; myGridView.DataBind(); dtAdapter = null; objConn.Close(); objConn = null; } void modDeleteCommand(Object sender, GridViewDeleteEventArgs e) { strConnString = "Server=localhost;UID=sa;PASSWORD=12345;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"; objConn.ConnectionString = strConnString; Label lblRoomID = (Label)myGridView.Rows[e.RowIndex].FindControl("lblRoomID"); strSQL = "DELETE FROM AddRoom WHERE RoomID = '" + lblRoomID.Text + "'"; objCmd.Connection = objConn; objCmd.CommandText = strSQL; objCmd.CommandType = CommandType.Text; ; objCmd.CommandText = strSQL; objConn.Open(); objCmd.ExecuteNonQuery(); myGridView.EditIndex = -1; BindData(); } void myGridView_RowDataBound(Object s, GridViewRowEventArgs e) { Label lblRoomID = (Label)(e.Row.FindControl("lblRoomID")); if (lblRoomID != null) { lblRoomID.Text = (string)DataBinder.Eval(e.Row.DataItem, "RoomID", "{0}"); } Label lblRoom = (Label)(e.Row.FindControl("lblRoom")); if (lblRoom != null) { lblRoom.Text = (string)DataBinder.Eval(e.Row.DataItem, "RoomName","{0}"); } Label lblSize = (Label)(e.Row.FindControl("lblSize")); if (lblSize != null) { lblSize.Text = (string)DataBinder.Eval(e.Row.DataItem, "Size", "{0}"); } Label lblSize1 = (Label)(e.Row.FindControl("lblSize1")); if (lblSize1 != null) { lblSize1.Text = (string)DataBinder.Eval(e.Row.DataItem, "Projectors", "{0}"); } Label lblSize2 = (Label)(e.Row.FindControl("lblSize2")); if (lblSize2 != null) { lblSize2.Text = (string)DataBinder.Eval(e.Row.DataItem, "Audio", "{0}"); } Label lblLocation = (Label)(e.Row.FindControl("lblLocation")); if (lblLocation != null) { lblLocation.Text = (string)DataBinder.Eval(e.Row.DataItem, "Location", "{0}"); } HyperLink hplEdit = (HyperLink)(e.Row.FindControl("hplEdit")); if (hplEdit != null) { hplEdit.NavigateUrl = "editRoomAdmin.aspx?RoomMeetID=" + (string)DataBinder.Eval(e.Row.DataItem, "RoomMeetID", "{0}"); } } void ShowPageCommand(Object s, GridViewPageEventArgs e) { myGridView.PageIndex = e.NewPageIndex; BindData(); }</script>