GridView绑定事件
1 数据绑定GridView时的事件
#region 数据绑定GridView时的事件
protected void GV_Data_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = Convert.ToInt32(e.Row.RowIndex.ToString());
LinkButton LB_Edit=e.Row.Cells[4].FindControl("LB_Modify") as LinkButton;
LB_Edit.CommandArgument = this.GV_Data.DataKeys[index]["Dic_Id"].ToString();
LinkButton LB_Del = e.Row.Cells[4].FindControl("LB_Del") as LinkButton;
LB_Del.Attributes.Add("onclick","javascript : return confirm('是否确认删除?')");
LB_Del.CommandArgument = this.GV_Data.DataKeys[index]["Dic_Id"].ToString();
//设置行样式,当鼠标移动到该行时变色
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4F4FD'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
}
}
#endregion
2 点击列表上的超链接所产生的事件
#region 点击列表上的超链接所产生的事件
protected void GV_Data_RowCommand(object sender, GridViewCommandEventArgs e)
{
//如果点击的是编辑
if (e.CommandName == "Modify")
{
}
//如果点击的是删除
if (e.CommandName == "Del")
{
}
}
#endregion