zoukankan      html  css  js  c++  java
  • asp的gridview

    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 DBHelper;

    public partial class student : System.Web.UI.Page
    {
    public string id;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    ViewState["SortOrder"] = "stu_id";
    ViewState["OrderDire"] = "ASC";
    Bind();
    }
    }


    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    string sqlstr = "delete from t_student where stu_id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
    SqlHelper.ExecteNonQueryText(sqlstr, null);
    Response.Write("<script>alert('删除成功!')</script>");
    GridView1.EditIndex = -1;
    Bind();
    }


    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;
    }
    Bind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    this.GridView1.PageIndex = e.NewPageIndex;
    Bind();
    }

    public void Bind()
    {
    string sql = "select * from t_student where 1=1";
    DataTableCollection dc = SqlHelper.GetTableText(sql, null);
    DataView view = dc[0].DefaultView;
    string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
    view.Sort = sort;
    this.GridView1.DataSource = view;
    GridView1.DataKeyNames = new string[] { "stu_id" };//主键
    this.GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Write(id);

    }

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
    for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
    {
    CheckBox CheckBox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
    if (CheckBox.Checked == true)
    {
    id=GridView1.Rows[i].Cells[0].Text.ToString().Trim();
    }
    }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    Response.Redirect("student_detail.aspx?id="+id);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
    Response.Redirect("student_detail.aspx?stu_id=" + id);
    }
    }

  • 相关阅读:
    图的存储结构(精编)
    二叉树的输入
    哈夫曼树及编码
    C. Bits (Codeforces Round #276 (Div. 2) )
    C++ Map 容器
    POJ 1080 Human Gene Functions(dp)
    数和二叉树——二叉树的建立及应用(遍历等)(基础篇)
    数独问题的介绍及POJ 2676-Sudoku(dfs+剪枝)
    【数据结构】——稀疏矩阵转置
    POJ 3083 Children of the Candy Corn
  • 原文地址:https://www.cnblogs.com/mengluo/p/6060627.html
Copyright © 2011-2022 走看看