• 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);
    }
    }

  • 相关阅读:
    上下伸展的JS菜单
    [ZZ]Debug VBScript with Visual Studio
    面试总结之杂题
    [ZZ]9 Confusing Naming Conventions for Beginners
    Robocopy
    [ZZ]什么是Alpha,Beta,RC,RTM,CTP版
    使用位运算交换两个值,不用临时变量
    学习笔记之编程之美微软技术面试心得(一)
    C#中如何获取系统环境变量
    学习笔记之SQL教程 from W3School
  • 原文地址:https://www.cnblogs.com/mengluo/p/6060627.html
Copyright © 2020-2023  润新知