GridView中添加自动编号,以及鼠标经过时行背景色变和删除时提示。

 1     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 2     {
 3         //如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet 
 4         if (e.Row.RowType == DataControlRowType.DataRow)
 5         {
 6             ////鼠标经过时,行背景色变
 7             //e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
 8             ////鼠标移出时,行背景色变
 9             //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
10 
11             ////当有编辑列时,避免出错,要加的RowState判断
12             //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
13             //{
14             //    ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
15             //}
16 
17         }
18         if (e.Row.RowIndex != -1)
19         {
20             int id = e.Row.RowIndex + 1;
21             e.Row.Cells[0].Text = id.ToString();
22         }
23 
24     }

posted @ 2007-04-11 17:25  电工男  阅读(453)  评论(0编辑  收藏  举报