1.对gridview进行绑定 并分页操作
protected void GV_Bind()
{
DataTable dt = new DataTable();
if (txt_Search.Text.Trim() == "")
dt = g_cc.GetList(this.GetUserID()).Tables[0];
else
dt = g_cc.GetSearch(txt_Search.Text.Trim(), this.GetUserID());
PagedDataSource objPDS = new PagedDataSource();
AspNetPager1.RecordCount = dt.Rows.Count;
Lbl_count.Text = dt.Rows.Count.ToString();
objPDS.DataSource = dt.DefaultView;
objPDS.AllowPaging = true;
objPDS.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
objPDS.PageSize = AspNetPager1.PageSize;
GV_SearchDetail.DataSource = objPDS;
GV_SearchDetail.DataKeyNames = new string[] { "ID" };
GV_SearchDetail.DataBind();
}
2. 鼠标经过效果
protected void GV_SearchDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#dbebfc'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
3 出发控件内事件
protected void GV_SearchDetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
string id = e.CommandArgument.ToString();
g_cc.Delete(int.Parse(id));
GV_Bind();
}
}