欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

为GridView的行添加鼠标经过、点击事件的小例子

程序员文章站 2024-02-27 15:15:27
复制代码 代码如下:   protected void gridview1_rowdatabound(object sender, gridviewro...
复制代码 代码如下:

   protected void gridview1_rowdatabound(object sender, gridviewroweventargs e)
    {
        e.row.attributes.add("onmouseover", "c=this.style.backgroundcolor;this.style.backgroundcolor='#95b8ff'");
        e.row.attributes.add("onmouseout", "this.style.backgroundcolor=c");
        e.row.attributes["style"] = "cursor:hand";
        int count = gridview1.rows.count;
        string id = "";
        for (int i = 0; i < count; i++)
        {
            id = gridview1.datakeys[i].value.tostring();
            gridview1.rows[i].attributes.add("onclick", "newwin=window.open('default3.aspx?id=" + id + "','newwin','width=500,height=550')");
        }
    }