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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值