datalist 鼠标在某行变色

liusaup 2009-05-03 02:05:43
如何使 datalist 鼠标在某行,某行变色
...全文
320 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
jyy_Emirates 2009-06-29
  • 打赏
  • 举报
回复
唉好可惜呀,已经结贴了,呜哇哇
jyy_Emirates 2009-06-28
  • 打赏
  • 举报
回复
在设计页面添加了DataList控件后,我在使用DataList绑定数据时是通过单元格来绑定的,因此鼠标效果就在源代码页面去实现,如下例所示

<asp:DataList ID="DataList1" runat="server" BorderWidth="1" >
<ItemTemplate>
<tr onmouseover="this.style.backgroundColor='#8EC26F'" onmouseout="this.style.backgroundColor=''" >
<td>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Area") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate>
Header1</td>
<td>Header2
</HeaderTemplate>
</asp:DataList>


如果你是div 的话,可以在整个行的div里面放上onmouseover="this.style.backgroundColor='#8EC26F'" onmouseout="this.style.backgroundColor=''",就好了,我亲自做的,不会错的
中年秃头大叔 2009-05-03
  • 打赏
  • 举报
回复
protected void datalist_ItemDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Item.ItemType == DataControlRowType.DataItem)
{
e.Item.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
中年秃头大叔 2009-05-03
  • 打赏
  • 举报
回复
protected void datalist_ItemDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Item.RowType == DataControlRowType.DataRow)
{
e.Item.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}


和gridview差不多的啦。。。
Adechen 2009-05-03
  • 打赏
  • 举报
回复
与2的类似,
添加Attribute
dengyun_1223 2009-05-03
  • 打赏
  • 举报
回复
学习
陌上花花 2009-05-03
  • 打赏
  • 举报
回复
学习了,帮顶了。
zhengli190602169 2009-05-03
  • 打赏
  • 举报
回复
来晚了
2楼的可以用
皓月明 2009-05-03
  • 打赏
  • 举报
回复
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}

指间、魔法师 2009-05-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 greymouseyu 的回复:]
做过gridview的,没做过datalist的:


C# code
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Row.Attributes.Add("onmouseout", "this.style.ba…
[/Quote]

假如一个页面有多个地方要变色的话,可以吧JS部分写在源中,然后调用
rx02120904 2009-05-03
  • 打赏
  • 举报
回复
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}

namhyuk 2009-05-03
  • 打赏
  • 举报
回复
类似2楼的作法,利用javascript可以操作DOM树内的元素这个原则,根据鼠标动作改变某元素的背景。
当然也可以动态地它指定不同的CSS class,如果按2楼作法,从精练程度上讲就显得不足了。毕竟那样做是给每一行都添加了类似逻辑的代码。
原则上你应该把这个改变背景动作的逻辑单独分离出来,放到一个单独的js方法里。
greymouseyu 2009-05-03
  • 打赏
  • 举报
回复
做过gridview的,没做过datalist的:


protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#e0ffff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}
insus 2009-05-03
  • 打赏
  • 举报
回复

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧