[转][ASP.NET]GridView点击行触发SelectedIndexChanged事件

1、在<% @Page ...... %>指令中添加 EnableEventValidation="false"

 

2、在RowDataBound事件中添加

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{      
        switch (e.Row.RowType)
        {
            case 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
                break;
        }

    }

   3、在第一二步之后就可以在SelectedIndexChanging和SelectedIndexChanged事件中添加处理逻辑了。

 

来源:http://xieycms.blog.163.com/blog/static/281213902010123105350751/ 

转载于:https://www.cnblogs.com/tukzer/archive/2010/11/28/1890571.html

你可能感兴趣的:([转][ASP.NET]GridView点击行触发SelectedIndexChanged事件)