如何在ASP.NET中实现DataGrid生成表格的鼠标所在行颜色的改变~~~?

qqrong1 2003-09-04 12:04:28
怎莫办呢。
...全文
22 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chnking 2003-09-04
  • 打赏
  • 举报
回复
private void DataGrid1_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","this.style.backgroundColor='#dddddd'") ;
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#ffffff'") ;
}
}
cpp2017 2003-09-04
  • 打赏
  • 举报
回复
加一个可以选中的当前行的
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("style","cursor:hand");
e.Item.Attributes.Add("onclick","beforeClickColor=currentcolor;if(curSelTr!=null){curSelTr.style.backgroundColor=beforeClickColor;curSelTr.style.color='#000000'}curSelTr=this;");
e.Item.Attributes.Add("onmouseover","if(typeof(curSelTr)=='undefined') {curSelTr= null;}currentcolor=this.style.backgroundColor;this.style.backgroundColor='#336699';this.style.color='#ffffff'");
e.Item.Attributes.Add("onmouseout","if(curSelTr!=this){this.style.backgroundColor=currentcolor;this.style.color='#000000'}");

}
}
qiuji 2003-09-04
  • 打赏
  • 举报
回复
在DataGrid的ItemDataBound事件中添加:

if(e.Item.ItemIndex!=-1)
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor);this.style.cursor='hand',this.style.backgroundColor='#dddddd'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
}
asam2183 2003-09-04
  • 打赏
  • 举报
回复
Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
End If
End Sub
rice139301 2003-09-04
  • 打赏
  • 举报
回复
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes["onClick"] = Page.GetPostBackClientHyperlink(LinkButton1, e.Item.ItemIndex.ToString());//e.Item.ItemIndex);
e.Item.Attributes.Add("style","cursor:hand");

e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFFCC'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");

}
}

62,046

社区成员

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

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

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

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