GridView 点击行的任意处触发选择事件

 

    protected override void Render(HtmlTextWriter writer)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {

            if (row.RowType == DataControlRowType.DataRow)
            {
                row.Attributes["onclick"] = ClientScript.GetPostBackEventReference(GridView1, "Select$" + row.RowIndex.ToString(), true);
                row.Attributes["style"] = "cursor:pointer";
                row.Attributes["title"] = "单击选择行";
                row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
                row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
            }
        }
        base.Render(writer);
    }

 

posted @ 2012-06-03 09:28  超级梨子  阅读(363)  评论(0编辑  收藏  举报