⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editstudent.aspx.cs

📁 程序学生信息管理系统(SQL2000+ASP.NET+c#+)
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
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 SMS;

public partial class _Default : System.Web.UI.Page
    
{
    OPDataBase OP = new OPDataBase();
    SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=Stuinform;Integrated Security=True");
       static string  Sql= "select StudentID,ClassID,Name,Age,Sex from student ";
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
          GridView1.Attributes.Add("style", "table-layout:fixed");

          if ((int)Session["Power"] != 0)
          {
              GridView1.Columns[5].Visible = false;
              GridView1.Columns[6].Visible = false;
          }
    }
    public void bind()
    {
      
        SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=Stuinform;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter(Sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "StudentID" };
        GridView1.DataBind();
        conn.Close();
      
      
    
     
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            GridView1.PageIndex = e.NewPageIndex;
            bind();
        }
        catch { }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string str = "delete from student where  StudentID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        SqlCommand cmd = new SqlCommand(str ,conn );
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        bind();
      
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;

        bind();

    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string sqlstr = "update student set ClassID='"
          + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Name='"
          + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',Age='"
          + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Sex='"
          + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where StudentID='"
           +GridView1 .DataKeys [e.RowIndex ].Value .ToString ()+"'";
        SqlCommand cmd = new SqlCommand(sqlstr ,conn );
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    protected void chaxun_btn_Click(object sender, EventArgs e)
    {

        object x = Infor_box.Text.ToString();
     string y = DropDownList1.SelectedValue.ToString();




   Sql  = "select *from student where " + y + " = '" + x + "'";
   
        try
        {

            OP.BinData(Sql ,GridView1);


          
            //OP.BinData(sql ,GridView1 );
            //Response.Write("<script> alert('成功!')</script>");
       

        }
        catch(Exception ex)
        { 
            string a=ex .Message .ToString ();
            Label2.Text = a;

       
           
        }
        finally
        {
            conn.Close();
            
        }

       

    }
   
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标经过时,行背景色变 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
            //鼠标移出时,行背景色变 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
            //((ImageButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('你确认要删除吗?')");
            //如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet 
            e.Row.Cells[0].ControlStyle.Width = Unit.Pixel(50);
           

        }

    }

    protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
    {
        Sql = "select StudentID,ClassID,Name,Age,Sex from student ";
        OP.BinData(Sql, GridView1);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -