#region 声明
//----------------------------------------------------------------------
//
// datagrid填充数据后颜色界面动态显示
//
// 作者: 李淼(Nick.Lee)
//
// 在ASP.NET环境下完整的 datagrid填充数据后界面动态显示填充方案
//
// datagrid界面动态显示
//
//
//----------------------------------------------------------------------
#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
}
}