📄 coursemanage.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data.Linq;
public partial class CourseManage : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if (!Page.IsPostBack)
{
///绑定控件的数据
BindCourseData();
}
///添加删除确认对话框
deleteBtn.Attributes.Add("onclick","return confirm('" + ASPNET35System.OPERATIONDELETEMESSAGE + "');");
}
private void BindCourseData()
{
///定义获取数据的类
CourseM course = new CourseM();
Table<Course> recc = course.GetCourses();
///设定控件的数据源
CourseList.DataSource = recc;
///设定控件的Text属性和Value属性
CourseList.DataTextField = "Desn";
CourseList.DataValueField = "CourseID";
///绑定控件的数据
CourseList.DataBind();
}
protected void AddBtn_Click(object sender,EventArgs e)
{
///跳转到添加页面
Response.Redirect("~/DesktopModules/Course/AddCourse.aspx");
}
protected void deleteBtn_Click(object sender,ImageClickEventArgs e)
{
if (CourseList.SelectedIndex > -1)
{
///定义类Course
CourseM course = new CourseM();
try
{
///删除
course.DeleteCourse(Int32.Parse(CourseList.SelectedValue));
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONDELETESUCCESSMESSAGE + "')</script>");
///重新绑定数据
BindCourseData();
}
catch (Exception ex)
{
///显示添加操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET35System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
protected void editBtn_Click(object sender,ImageClickEventArgs e)
{
if (CourseList.SelectedIndex > -1)
{
///跳转到查看页面
Response.Redirect("~/DesktopModules/Course/UpdateCourse.aspx?CourseID=" + CourseList.SelectedValue);
}
else
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -