【文件属性】:
文件名称:gridview 简单代码
文件大小:3KB
文件格式:CS
更新时间:2012-07-08 18:59:31
gridview
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getData();
}
}
//得到数据
public void getData()
{
this.GridView1.DataSource = BLL.mesManager.getGridData();
this.GridView1.DataBind();
}
// 绑定之后发生
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtn = (LinkButton)e.Row.FindControl("LinkButton2");
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
string aa = e.Row.Cells[3].Text.ToString();
lbtn.Attributes.Add("OnClick", "return confirm('您确认要删除吗?')");
}
}
//发生时间时激发
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
int id = Convert.ToInt32(e.CommandArgument);
int resultNum = BLL.mesManager.del(id);
if (resultNum > 0)
{
Response.Write("");
getData();
}
else
{
Response.Write("");
}
}
else if (e.CommandName == "upd")
{
int id = Convert.ToInt32(e.CommandArgument);
Response.Redirect("Update.aspx?id=" + id);
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
}
//pageindexchangeing
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
getData();
}
//全部删除
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
int id=Convert.ToInt32( this.GridView1.Rows[i].Cells[1].Text);
BLL.mesManager.del(id);
}
}
getData();
}
}