.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
[原创]在ASP.NET环境下完整的datagrid填充数据后界面动态显示填充方案

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

#region 声明
//----------------------------------------------------------------------
//
// datagrid填充数据后颜色界面动态显示
//
// 作者: 李淼(Nick.Lee)
//
// 在ASP.NET环境下完整的 datagrid填充数据后界面动态显示填充方案
//
//  datagrid界面动态显示
//
// [email protected]
//
//----------------------------------------------------------------------
#endregion
using System;

#region 引用命名空间
using System.Web.UI;
using System.Web.UI.WebControls;
#endregion


namespace NickLee.Web.UI
{
 /// <summary>
 /// DataGrid扩充
 /// </summary>
 public class webGridFill
 {
  public webGridFill()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  #region DataGrid界面动态显示函数
  /// <summary>
  /// 界面显示扩充函数,设置颜色请先在datagrid的ItemStyle.BackColor设置单行颜色,AlternatingItemStyle.BackColor设置双行颜色
  /// </summary>
  /// <param name="sender">需要传入的datagrid名称</param>
  /// <param name="mouseOverColor">鼠标到当前行时的颜色</param>
  /// <param name="clickColor">鼠标在当前行单击的颜色</param>
  public void interFaceExtend(System.Web.UI.WebControls.DataGrid sender,string mouseOverColor,string clickColor)
  {

   if (sender.ItemStyle.BackColor.Name=="0" )
   {
    //条件判断
    if(sender.AlternatingItemStyle.BackColor.Name=="0")
    {
     //条件判断
     for(int i=0;i<sender.Items.Count;i++)
      //循环每个数据项
     {
      sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffff';this.style.cursor='hand'");
      //对sender添加附加事件"onMouseOut",并设定表格的背景色和鼠标指针样式
      sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
      //对sender添加附加事件"onmouseOver",并设定表格的背景色和鼠标指针样式
      sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
      //对sender添加附加事件"onClick",并设定表格的背景色和鼠标指针样式

     }
    }
    else
    {
     if (sender.AlternatingItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)))==0)
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffff';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }
     }
     else
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffff';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.AlternatingItemStyle.BackColor.Name+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }
     }
    }
   }
   else
   {
    if(sender.AlternatingItemStyle.BackColor.Name=="0")
    {
     if (sender.ItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.ItemStyle.BackColor.Name.Remove(0,2)))==0)
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.ItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
       sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
       sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
      }

     }
     else
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.ItemStyle.BackColor.Name+"';this.style.cursor='hand';");
       sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
       sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
      }
     }
    }
    else
    {
     if ((sender.AlternatingItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)))!=0) && (sender.ItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.ItemStyle.BackColor.Name.Remove(0,2)))==0))
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.ItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.AlternatingItemStyle.BackColor.Name+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }
     }
     else if ((sender.AlternatingItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)))==0) && (sender.ItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.ItemStyle.BackColor.Name.Remove(0,2)))!=0))
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.ItemStyle.BackColor.Name+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }
     }
     else if((sender.AlternatingItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)))!=0) && (sender.ItemStyle.BackColor.Name.CompareTo("ff"+Convert.ToString(sender.ItemStyle.BackColor.Name.Remove(0,2)))!=0))
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.ItemStyle.BackColor.Name+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='"+sender.AlternatingItemStyle.BackColor.Name+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }

     }
     else
     {
      for(int i=0;i<sender.Items.Count;i++)
      {
       if (i % 2 == 0)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.ItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
       else if(i % 2 == 1)
       {
        sender.Items[i].Attributes.Add("onMouseOut","this.style.backgroundColor='#"+sender.AlternatingItemStyle.BackColor.Name.Remove(0,2)+"';this.style.cursor='hand';");
        sender.Items[i].Attributes.Add("onmouseOver","this.style.backgroundColor='"+mouseOverColor+"'");
        sender.Items[i].Attributes.Add("onClick","this.style.backgroundColor='"+clickColor+"'");
       }
      }
     }
     
    }
   
   }
  }


  #endregion

 }
}




相关文章

相关软件