博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP。net 之view
阅读量:5007 次
发布时间:2019-06-12

本文共 7066 字,大约阅读时间需要 23 分钟。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
网页查询
到第

  

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using MySql.Data.MySqlClient;using DBHelper;public partial class Index : System.Web.UI.Page{    Student stu_s = new Student();        protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)         {            ViewState["SortOrder"] = "stu_id";            ViewState["OrderDire"] = "ASC";            BindView();        }    }    public void BindView()     {        string names = "";        if (!string.IsNullOrEmpty(this.TextBox1.Text)) {            names += " and stu_name like '" + this.TextBox1.Text + "%'";                }        DataView view=stu_s.GetTableSet(names);        string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];        view.Sort = sort;        GridView1.DataSource = view;        GridView1.DataKeyNames = new string[] { "stu_id" };        GridView1.DataBind();        //GridView1.BottomPagerRow.Visible = true;        //GridViewRow pagerow = GridView1.BottomPagerRow;                   }    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)    {        GridView1.PageIndex = e.NewPageIndex;        BindView();    }    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)    {        GridViewRow pagerRow = GridView1.BottomPagerRow;        DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("DropDownList1");        GridView1.PageIndex = pageList.SelectedIndex;        BindView();    }    protected void GridView1_DataBound(object sender, EventArgs e)    {                //GridViewRow pagerRow = GridView1.BottomPagerRow;        //DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("DropDownList1");        //if (pageList != null)        //{                    //    for (int i = 0; i < GridView1.PageCount; i++)        //    {               //        int pageNumber = i + 1;        //        ListItem item = new ListItem(pageNumber.ToString());                       //        if (i == GridView1.PageIndex)        //        {        //            item.Selected = true;        //        }                       //        pageList.Items.Add(item);        //    }        //}                       }    protected void Button1_Click(object sender, EventArgs e)    {              }    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)    {        string sPage = e.SortExpression;        if (ViewState["SortOrder"].ToString() == sPage)        {            if (ViewState["OrderDire"].ToString() == "Desc")                ViewState["OrderDire"] = "ASC";            else                ViewState["OrderDire"] = "Desc";        }        else        {            ViewState["SortOrder"] = e.SortExpression;        }        BindView();    }    protected void Button1_Click1(object sender, EventArgs e)    {        //if (this.TextBox1.Text == "")        //{        //    BindView();        //}        //else         //{        //    string names = this.TextBox1.Text.Trim();        //    DataView view = stu_s.GetTableViewString(names);                  //    GridView1.DataSource = view;        //    GridView1.DataKeyNames = new string[] { "stu_id" };        //    GridView1.DataBind();                //}        BindView();            }    protected void Button5_Click(object sender, EventArgs e)    {        Response.Redirect("AddStudent.aspx");    }    protected void Button2_Click(object sender, EventArgs e)    {        string id="";        for (int i = 0; i < GridView1.Rows.Count - 1; i++) {            CheckBox ckb = (CheckBox)GridView1.Rows[i].FindControl("Checkbox1");            if (ckb.Checked == true) {                id = GridView1.DataKeys[i].Value.ToString();            }                }        Response.Redirect("AddStudent.aspx?id=" + id);    }    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)    {        string sqlstr = "delete from t_student where stu_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";        DBHelper.SqlHelper.ExecteNonQueryText(sqlstr);        Response.Write("");        GridView1.EditIndex = -1;        BindView();    }    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {          //如果是绑定数据行        if (e.Row.RowType == DataControlRowType.DataRow)        {            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)            {                ((LinkButton)e.Row.Cells[11].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:" + e.Row.Cells[3].Text + "吗?')");            }            //首先判断是否是数据行            if (e.Row.RowType == DataControlRowType.DataRow)            {                //当鼠标停留时更改背景色                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");                //当鼠标移开时还原背景色                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");            }            //如果是绑定数据行            if (e.Row.RowType == DataControlRowType.DataRow)            {                //鼠标经过时,行背景色变                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");                //鼠标移出时,行背景色变                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");            }        }            }    protected void Button3_Click(object sender, EventArgs e)    {        string id = "";        for (int i = 0; i < GridView1.Rows.Count - 1; i++)        {            CheckBox ckb = (CheckBox)GridView1.Rows[i].FindControl("Checkbox1");            if (ckb.Checked == true)            {                id = GridView1.DataKeys[i].Value.ToString();            }        }        int x = stu_s.GetDelStudent(id);        if (x > 0)        {            Response.Write("");        }        else {            Response.Write("");        }        BindView();    }}

  

转载于:https://www.cnblogs.com/mengluo/p/6068122.html

你可能感兴趣的文章
PE破解win2008登录密码
查看>>
JVM垃圾回收机制
查看>>
结对编程2 微软学术搜索 第一部分——功能性bug
查看>>
StarUML
查看>>
程序员需要有多懒 ?- cocos2d-x 数学函数、常用宏粗整理 - by Glede
查看>>
利用Clojure统计代码文件数量和代码行数
查看>>
课时23:递归:这帮小兔崽子
查看>>
RobotFrameWork接口报文测试-----(三)demo的加强版(数据驱动测试)
查看>>
NetBeansRCP-添加/修改NetBeans的JVM启动参数
查看>>
Linux c获取时间
查看>>
css中设置background属性
查看>>
第九周作业
查看>>
[leedcode 70] Climbing Stairs
查看>>
学习 WCF (1)--基础篇
查看>>
sql server 2008学习4 设计索引的建议
查看>>
vim 插件之vundle
查看>>
数据库多对多关联表(Python&MySQL)
查看>>
[实变函数]1.2 集合的运算
查看>>
第06天
查看>>
设计模式的征途—5.原型(Prototype)模式
查看>>