GridView触发SelectedIndexChanged和SelectedIndexChanging方法
1.<%@ Page ... EnableEventValidation="false"%> 在页面头中加入EnableEventValidation="false"
2.在GridView_RowDataBound方法中加入以下代码段
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["style"] = "cursor:hand";
#region //点击行触发SelectedIndexChanged事件
PostBackOptions myPostBackOptions = new PostBackOptions(this);
myPostBackOptions.AutoPostBack = false;
myPostBackOptions.PerformValidation = false;
myPostBackOptions.RequiresJavaScriptProtocol = true; //加入javascript:头
String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
e.Row.Attributes.Add("onclick", evt);
#endregion
}
}

浙公网安备 33010602011771号