刘刚博客

gridview 单击行时如何让SelectedIndexChanging事件响应

在gridview控件上单击行的时候,是不触发SelectedIndexChanging事件的,那么想要单击时触发SelectedIndexChanging事件时怎么做呢?

我是这样做的:

在gridview的行绑定事件

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
        }

 

加上这些之后,在点击行时就可以触发SelectedIndexChanging事件了。

posted @ 2014-07-25 14:43  Future.Net博客  阅读(783)  评论(0编辑  收藏  举报