📄 student.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace sms
{
/// <summary>
/// student 的摘要说明。
/// </summary>
public partial class student : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton Lbtn_student;
private string strsql;
private DataAccess DataAs;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
Bindgrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void Btn_search_Click(object sender, System.EventArgs e)
{
Pnl_sort.Visible=true;
}
protected void Btn_all_Click(object sender, System.EventArgs e)
{
Pnl_sort.Visible=false;
Bindgrid();
}
//public void DataGrid_Page(object sender,DataGridPageChangedEventArgs e)
//{
// Dgd_student.CurrentPageIndex=e.NewPageIndex;
// Bindgrid();
//}
//public void DataGrid_cancel(object sender,DataGridCommandEventArgs e)
//{
// Dgd_student.EditItemIndex=-1;
// Bindgrid();
//}
//public void DataGrid_edit(object sender,DataGridCommandEventArgs e)
//{
// Dgd_student.EditItemIndex=(int)e.Item.ItemIndex;
// Bindgrid();
//}
//public void DataGrid_update(object sender,DataGridCommandEventArgs e)
//{
// strsql="update student set Student_name='"+((TextBox)e.Item.Cells[1].Controls[0]).Text+"',Student_sex='"+((TextBox)e.Item.Cells[2].Controls[0]).Text+"',Student_nation='"+((TextBox)e.Item.Cells[3].Controls[0]).Text
// + "',Student_birthday='" + ((TextBox)e.Item.Cells[4].Controls[0]).Text + "',Student_time='" + ((TextBox)e.Item.Cells[5].Controls[0]).Text + "',Student_classid='" + ((TextBox)e.Item.Cells[6].Controls[0]).Text + "',Student_home='" + ((TextBox)e.Item.Cells[7].Controls[0]).Text + "',Student_else='" + ((TextBox)e.Item.Cells[8].Controls[0]).Text + "' where Student_id='" + Dgd_student.DataKeys[(int)e.Item.ItemIndex]+"'";
// DataAs = new DataAccess();
// bool Result = DataAs.ExecSql(strsql);
// if (Result)
// {
// Lbl_note.Text="编辑成功";
// Dgd_student.EditItemIndex=-1;
// }
// else
// {
// Lbl_note.Text="编辑失败,请检查输入!";
// Lbl_note.Style["color"]="red";
// }
// Bindgrid();
//}
//public void DataGrid_delete(object sender,DataGridCommandEventArgs e)
//{
// strsql = "delete from student where Student_id='" + Dgd_student.DataKeys[(int)e.Item.ItemIndex]+"'";
// DataAs = new DataAccess();
// bool Result = DataAs.ExecSql(strsql);
// if (Result)
// {
// Lbl_note.Text="删除成功";
// }
// else
// {
// Lbl_note.Text="删除失败";
// Lbl_note.Style["color"]="red";
// }
// Bindgrid();
//}
public void Bindgrid()
{
strsql="select * from student";
DataAs = new DataAccess();
DataTable DT = DataAs.CreateDatatable(strsql);
GridView1.DataSource = DT;
GridView1.DataBind();
}
protected void Btn_ok_Click(object sender, System.EventArgs e)
{
strsql="select * from student where Student_id='"+Tbx_sortid.Text+"'or Student_name='"+Tbx_name.Text+"'";
DataAs = new DataAccess();
DataTable DT = DataAs.CreateDatatable(strsql);
GridView1.DataSource= DT;
GridView1.DataBind();
}
protected void Lbtn_course_Click(object sender, System.EventArgs e)
{
Response.Redirect("course.aspx");
}
protected void Lbtn_sortcourse_Click(object sender, System.EventArgs e)
{
Response.Redirect("student_course.aspx");
}
protected void Lbtn_add_Click(object sender, System.EventArgs e)
{
Response.Redirect("addstudent.aspx");
}
protected void Btn_exit_Click(object sender, System.EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
protected void Lbtn_grade_Click(object sender, System.EventArgs e)
{
Response.Redirect("grade_manage.aspx");
}
protected void Lbtn_addclass_Click(object sender, System.EventArgs e)
{
Response.Redirect("classes.aspx");
}
protected void Lbtn_addteacher_Click(object sender, System.EventArgs e)
{
Response.Redirect("teacher.aspx");
}
private void Lbtn_student_Click(object sender, System.EventArgs e)
{
Response.Redirect("student.aspx");
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
strsql = "delete from student where Student_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
DataAs = new DataAccess();
bool Result = DataAs.ExecSql(strsql);
if (Result)
{
Lbl_note.Text = "删除成功";
}
else
{
Lbl_note.Text = "删除失败";
Lbl_note.Style["color"] = "red";
}
Bindgrid();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex ;
Bindgrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvr = GridView1.Rows[GridView1.EditIndex];
e.NewValues["Student_name"] = ((TextBox)gvr.Cells[1].Controls[0]).Text;
e.NewValues["Student_sex"] = ((TextBox)gvr.Cells[2].Controls[0]).Text;
e.NewValues["Student_nation"] = ((TextBox)gvr.Cells[3].Controls[0]).Text;
e.NewValues["Student_birthday"] = ((TextBox)gvr.Cells[4].Controls[0]).Text;
e.NewValues["Sturdent_time"] = ((TextBox)gvr.Cells[5].Controls[0]).Text;
e.NewValues["Student_classid"] = ((TextBox)gvr.Cells[6].Controls[0]).Text;
e.NewValues["Student_home"] = ((TextBox)gvr.Cells[7].Controls[0]).Text;
e.NewValues["Student_else"] = ((TextBox)gvr.Cells[8].Controls[0]).Text;
strsql = "update student set Student_name='" + ((TextBox)gvr.Cells[1].Controls[0]).Text + "',Student_sex='" + ((TextBox)gvr.Cells[2].Controls[0]).Text + "',Student_nation='" + ((TextBox)gvr.Cells[3].Controls[0]).Text
+ "',Student_birthday='" + ((TextBox)gvr.Cells[4].Controls[0]).Text + "',Sturdent_time='" + ((TextBox)gvr.Cells[5].Controls[0]).Text + "',Student_classid='" + ((TextBox)gvr.Cells[6].Controls[0]).Text
+ "',Student_home='" + ((TextBox)gvr.Cells[7].Controls[0]).Text + "',Student_else='" + ((TextBox)gvr.Cells[8].Controls[0]).Text + "' where Student_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
DataAs = new DataAccess();
bool Result = DataAs.ExecSql(strsql);
if (Result)
{
Lbl_note.Text = "编辑成功";
GridView1.EditIndex = -1;
}
else
{
Lbl_note.Text = "编辑失败,请检查输入!";
Lbl_note.Style["color"] = "red";
}
Bindgrid();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Bindgrid();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Bindgrid();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -