现在的位置: 首页 > 综合 > 正文

GridView行单击事件

2013年05月30日 ⁄ 综合 ⁄ 共 1109字 ⁄ 字号 评论关闭

1、在页面中添加 EnableEventValidation="false"

2、添加回调事件

protected void gvtest_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["style"] = "cursor:hand";
                #region
                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", "alert('测 试');" + evt);
                //e.Row.Attributes.Add("onclick", "javascirpt:__doPostBack('gvtest','Select$" + e.Row.RowIndex + "')");
                #endregion
            }
        }

3、行单击的处理事件,没有实现Ajax

        protected void gvtest_SelectedIndexChanged(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('" + gvtest.SelectedRow.Cells[2].Text + "');", true);
        }

抱歉!评论已关闭.