请问:如何实现让鼠标移到某一行让这一行变颜色?我是新手
请帮助!!! 问题点数:20、回复次数:8Top
1 楼coldpanth(^War3^)回复于 2006-03-03 11:52:47 得分 0
<tr onmouseover="this.style.backgroundColor='#000000'">Top
2 楼daishengs(横舟摆渡)回复于 2006-03-03 12:13:58 得分 0
private void InitializeComponent()
{
this.dgMouseOver.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.changeRowColor);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
// ItemDataBound事件
private void changeRowColor(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果是数据项并且是交替项
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
}
}
private void DataGridDataBind()
{
//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
//创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter("select LastName,FirstName,Title,TitleOfCourtesy,City from Employees",conn);
//创建DataSet对象
DataSet ds = new DataSet();
try
{
//填充数据集
da.Fill(ds,"testTable");
//进行数据绑定
dgMouseOver.DataSource = ds.Tables["testTable"];
dgMouseOver.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}Top
3 楼jiangpan()回复于 2006-03-03 12:36:30 得分 0
对不起我想问的是在DataGrid控件中实现这个功能....不好意思刚才忘打了!!!Top
4 楼ljhkim6()回复于 2006-03-03 12:50:53 得分 0
ItemDataBind( object Sender, ....)
在这个事件中写
要代码的话我给你,我也记不清了。。。。
jiangsir6&163.com
Top
5 楼jxdyzwh(http://www.szsoftware.com.cn)回复于 2006-03-03 13:27:17 得分 0
在.CS中
private void dg1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","tdOver(this)");
e.Item.Attributes.Add("onmouseout","tdOut(this)");
}
}
在.aspx
<script>
var bColor='#ff3300'; //定义颜色,为单击时显示的颜色
var fColor='#fafafa'; //定义颜色,为单击时字体所显示的颜色
function tdOver(td)
{
if(td.style.backgroundColor!=bColor)//当这一列的背景颜色不为以上定义的颜色时
{
td.setAttribute('DtBg',td.style.backgroundColor);//得到这列的背景颜色并且设置为DtBg
td.setAttribute('DtCo',td.style.color);//得到这列的字体颜色并且设置为DtCo
td.style.color='#ff66cc';//设置鼠标移上时列里的字体颜色为#ff99ff
td.style.cursor='hand';//设置鼠标的形状为手状
td.style.backgroundColor='#66cc66';//设置该列的背景颜色为#66cc66
}
}
function tdOut(td)
{
if(td.style.backgroundColor!=bColor)//当这一列的背景颜色不为以上定义的颜色时
{
td.style.backgroundColor=td.getAttribute('DtBg');//设置该列的背景颜色为以上得到的颜色,即DtBg
td.style.color=td.getAttribute('DtCo');//设置该列的背景颜色为以上得到的颜色,即DtCo
}
}
</script>
Top
6 楼dh20156(风之石)回复于 2006-03-03 13:43:31 得分 0
学习.Top
7 楼flycantus(飞扬旋律)回复于 2006-03-03 13:47:48 得分 0
加上ItemDataBound事件:
private void dgResult_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#DFF0FF'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='white'");
}Top
8 楼lgnet(www.51bw.net)回复于 2006-03-03 14:08:20 得分 0
//鼠标移到表格数据行,颜色会变化
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//颜色交替
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#EAF5FF'");
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
if(e.Item.ItemType ==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
}Top
相关问题
- 请问如何实现当鼠标移动到按钮上,按钮上的文字自动变颜色
- 鼠标一碰到某一文字时,此文字就会变颜色,请问这怎么实现?
- 请问如何实现当鼠标停在静态文本控件上时,字就马上改变颜色?
- 请问怎样实现当鼠标移到按钮上时,按钮上的字变颜色,鼠标移出按钮后变回原来的颜色?
- listbox的某一行是否能改变颜色?
- 怎么样使table中的每条记录在鼠标over时变颜色??????????????急
- 当鼠标指向字体时如何使字体改变颜色?
- 当鼠标移动到单元格上时,DATALIST 不能改变颜色
- 在表中,如何使我点中的一行记录改变颜色?
- 请问怎样实现鼠标指向一个label时变颜色,而移走时又恢复默认的颜色呢?就象网页中的超级链接一样!




