阿太学.NET

.NET学习
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#999999'");//鼠标移动引起变色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");


            LinkButton btnDelete = (LinkButton)e.Row.FindControl("LinkButton1");   //添加删除效果 这样做可以把需要删除的详细信息进行显示
            btnDelete.Attributes.Add("onclick", "javascript:return " + "confirm('你确定要删除造型[" + DataBinder.Eval(e.Row.DataItem, "ZaoXingName") + "]吗?')"); 
                 
            //e.Row.Attributes["style"] = "Cursor:hand";//设置悬浮鼠标指针形状为"小手"  这个效果可以结合onclick事件来做其他的一些功能,如点击查看详细信息等等  选中此行等等

            //DataRowView row = (DataRowView)e.Row.DataItem;
            //string id = row["depId"].ToString();
            //e.Row.Attributes.Add("onclick", "select_" + e.Row.Cells[0].Text + ".checked=true;");
            //e.Row.Attributes.Add("onclick", "select_" + e.Row.Cells[0].Text + ".checked=true;selectx(this)");
        }
    }

通过这个事件还可以对GridView的行做很多事情,需要什么自己想想实现代码吧。。


还有 刚开始我在.cs文件中写了这个事件,但是没执行,晕忽忽的,在2003里面我知道去哪里注册事件,但是2005的CS文件里面我没找到,
原来是在前台文件里面 晕哈。。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="800px" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound">
其他我就不说了。。。
可能这些是些再基础不过的东西,但是我刚接触2005  什么都不知道就碰到问题了, 别笑我哈