1 Star 0 Fork 2

Nan/asp.net学生成绩管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AdminCourse.aspx.cs 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2023-02-12 22:31 . 更新添加项目文件。
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GradeMis
{
public partial class AdminCourse : System.Web.UI.Page
{
protected SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["GradeSys"]);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetData();//fdsf
}
}
protected void GetData()
{
string sql = string.Empty;
sql = string.Format("select * from 课程表");
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "t");
this.DataGrid1.DataSource = ds.Tables["t"];
this.DataGrid1.DataBind();
}
catch
{ }
}
protected void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("AdminCourseAdd.aspx");
}
protected void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
GetData();
}
protected void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sid = e.Item.Cells[0].Text;
string sql = string.Format("delete 课程表 where 课程号 = '{0}'", sid);
ExeSql(sql);
this.DataGrid1.EditItemIndex = -1;
GetData();
}
protected void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = -1;
GetData();
}
protected void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sid = e.Item.Cells[0].Text;
TextBox txtName = new TextBox();
txtName = (TextBox)e.Item.Cells[1].Controls[0];
string name = txtName.Text.ToString();
TextBox txtAge = new TextBox();
txtAge = (TextBox)e.Item.Cells[2].Controls[0];
string age = txtAge.Text.ToString();
string sql = string.Empty;
sql = string.Format("update 课程表 set 课程名='{0}',先修课='{1}' where 课程号='{2}'", name, age, sid);
ExeSql(sql);
this.DataGrid1.EditItemIndex = -1;
GetData();
}
protected void ExeSql(string sql)
{
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex);
}
finally
{
conn.Close();
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/x369/GradeMis.git
git@gitee.com:x369/GradeMis.git
x369
GradeMis
asp.net学生成绩管理系统
master

搜索帮助