zoukankan      html  css  js  c++  java
  • .NET中动态生成的表格,当鼠标经过tr时改变tr当前颜色,当鼠标移开恢复原来的颜色

    首先看看效果一:

     

    效果二:

     

     实现上面效果,Insus.NET 是使用下面例子进行修改:

     http://www.cnblogs.com/insus/archive/2012/10/29/2744721.html

     效果一变动代码如下:

    View Code
     //for each List<T> 
            Pager objPg = new Pager();
            objPg.PagerCollections().ForEach(delegate(Pager p)
            {
                TableRow tbr = new TableRow();
                tbr.ID = "tr" + p.ID.ToString();

                //设置背景颜色            
                tbr.BackColor = System.Drawing.Color.Green;

                //宣告一个变量,当mouse over or out样式
                string style = "this.style.backgroundColor='@BackColor'";

                //宣告一个变量,将存储行原来颜色。
                string bgColor = string.Empty;

                TableCell tc0 = new TableCell();
                tc0.Text = p.ID.ToString();
                tc0.BorderWidth = Unit.Pixel(1);
                tbr.Cells.Add(tc0);

                TableCell tc1 = new TableCell();
                tc1.Text = p.Size;
                tc1.BorderWidth = Unit.Pixel(1);
                tbr.Cells.Add(tc1);

                //获取行原来颜色。
                bgColor = tbr.BackColor.Name;

                //设置mouse over事件, 最后一个参数"blue"是mouse over时的颜色,你可以自行指定。
                tbr.Attributes.Add("onmouseover", style.Replace("@BackColor""blue"));

                //设置mouse out事件
                tbr.Attributes.Add("onmouseout", style.Replace("@BackColor", bgColor));

                oTable.Rows.Add(tbr);
            });

    效果二变动代码如下: 

    View Code
     //for each List<T> 
            Pager objPg = new Pager();
            objPg.PagerCollections().ForEach(delegate(Pager p)
            {
                TableRow tbr = new TableRow();
                tbr.ID = "tr" + p.ID.ToString();

                //设置背景颜色
                if (p.ID % 2 == 0)
                    tbr.BackColor = System.Drawing.Color.Green;
                else
                    tbr.BackColor = System.Drawing.Color.Silver;

                //宣告一个变量,当mouse over or out样式
                string style = "this.style.backgroundColor='@BackColor'";

                //宣告一个变量,将存储行原来颜色。
                string bgColor = string.Empty;

                TableCell tc0 = new TableCell();
                tc0.Text = p.ID.ToString();
                tc0.BorderWidth = Unit.Pixel(1);
                tbr.Cells.Add(tc0);

                TableCell tc1 = new TableCell();
                tc1.Text = p.Size;
                tc1.BorderWidth = Unit.Pixel(1);
                tbr.Cells.Add(tc1);

                //获取行原来颜色。
                bgColor = tbr.BackColor.Name;

                //设置mouse over事件, 最后一个参数"blue"是mouse over时的颜色,你可以自行指定。
                tbr.Attributes.Add("onmouseover", style.Replace("@BackColor""blue"));

                //设置mouse out事件
                tbr.Attributes.Add("onmouseout", style.Replace("@BackColor", bgColor));

                oTable.Rows.Add(tbr);
            });
  • 相关阅读:
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    预习非数值数据的编码方式
    计算机组成与系统结构作业01
    C语言||作业01
  • 原文地址:https://www.cnblogs.com/insus/p/2744769.html
Copyright © 2011-2022 走看看