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

📄 editusers.aspx.cs

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

public partial class _Default : System.Web.UI.Page
{
    OPDataBase op = new OPDataBase();
    static string Sql = "select UserName,Power,Password ,Sex from Users";
    protected void Page_Load(object sender, EventArgs e)
    {  //SqlConnection conn=new SqlConnection (op .getConnection ());
       //    conn.Open();
        if (!IsPostBack)
        {
            bind();
        
        }
        GridView1.Attributes.Add("style", "table-layout:fixed"); 
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            GridView1.PageIndex = e.NewPageIndex;
            bind();
            
        }
        catch { }

    }
    public void bind()
    {
        
        op.BinData(Sql , GridView1);
        GridView1 .DataKeyNames =new string[] {"UserName"};
    
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         Sql  = "select *from Users where "+DropDownList1.SelectedValue .ToString ()+"='"+TextBox_Infor .Text .Trim ()+"'";
         bind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string sql = "update  Users set UserName='" +
            ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',Password='" +
             ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim () + "',Power='" +
             ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "' where UserName='"
           + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        op.BindCommand(sql);
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string str = "delete from Users where  UserName='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        op.BindCommand(str);
        bind();
    }
    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 
        }

    }
    protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
    {
        Sql = "select UserName,Power,Password ,Sex from Users";
        op.BinData(Sql , GridView1);
        GridView1.DataKeyNames = new string[] { "UserName" };
    }
}

⌨️ 快捷键说明

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