如何实现鼠标在datagrid某一行上方时此行改变颜色?如何用程序控制某一行的颜色?

panxuegang 2004-12-27 05:25:37
谢谢
...全文
304 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
行路人怎么样 2005-08-19
  • 打赏
  • 举报
回复
marck
panxuegang 2004-12-30
  • 打赏
  • 举报
回复
大家如此帮忙,真是感谢万分,可惜手头分太少了,请大家见谅
hqz010 2004-12-29
  • 打赏
  • 举报
回复
学习
YIO2002 2004-12-29
  • 打赏
  • 举报
回复
e.Item.Attributes["onmouseover"]="TmpColor=this.style.backgroundColor;this.style.backgroundColor='#00cc99'";
e.Item.Attributes["onmouseout"]="this.style.backgroundColor=TmpColor";
这是交替色的实现
panxuegang 2004-12-28
  • 打赏
  • 举报
回复
谢谢大家的帮助,我明白了。还想问一下,怎样获得在变色前获得先前的backgroundColor,然后在onMouseOut时变成以前的颜色,datagrid以前是交替色的,现在鼠标晃过后都成一种颜色了。小弟太菜了,现在手头还没有参考书,请大家不吝赐教。
xueyhfeng 2004-12-27
  • 打赏
  • 举报
回复
正好有一段这样的代码,(不是我原创的)


[ASP.NET][原创]实现DataGrid1中感应鼠标经过,并可一行点击弹出窗口

很多人说很难,其实就这几行代码。只要在DataGrid1的ItemDataBound中写入下代码即可

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>=0) //此行可以删除掉
{
//弹出窗口代码
e.Item.Attributes.Add("onclick","window.open('WebForm2.aspx?ZoneNo="+e.Item.Cells[0].Text+"','','Toolbar=no')");
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#e9e9e9'; this.style.cursor='hand';");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#f7f7f7';");
}
}

再进一步
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType liy=(ListItemType)e.Item.ItemType;
if(liy==ListItemType.Header)
{
for(int i=0;i<e.Item.Cells.Count;i++)
{
e.Item.Cells[I.Attributes.Add("onclick","window.open('WebForm2.aspx?SortBy="+i.ToString()+"','','Toolbar=no')");
e.Item.Cells[I.Attributes.Add("onMouseOver","this.style.backgroundColor='#ff9933'; this.style.cursor='hand';");
e.Item.Cells[I.Attributes.Add("onMouseOut","this.style.backgroundColor='#FFE0C0';");
}
}
if(e.Item.ItemIndex>=0)
{
e.Item.Attributes.Add("onclick","window.open('WebForm2.aspx?ZoneNo="+e.Item.Cells[0].Text+"','','Toolbar=no')");
e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#e9e9e9'; this.style.cursor='hand';");
e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#f7f7f7';");
}
}
}
thinhunan 2004-12-27
  • 打赏
  • 举报
回复
完整的解决方案,讨厌那些动不动贴一堆来的人。
在DataGrid的数据绑定事件中写
if(e.Item.ItemType == ListItemType.Item||e.Item.ItemType == ListItemType.交替项(我不记得那个单词了))
{
//鼠标变色
e.Item.Attributes.Add("onmouseover","this.className='你要变成的那种样式名';");
e.Item.Attributes.Add("onmouseout","this.className='你要变回的那种样式名';");
//特定行变色
if((e.Item.ItemIndex%5) == 0)
e.Item..............
}
lonelydreamsym 2004-12-27
  • 打赏
  • 举报
回复
发错了,没看清题目,其实二楼的方法最省事了
lonelydreamsym 2004-12-27
  • 打赏
  • 举报
回复
楼上前几位的是在前台写的,后台写在OnItemCreated然后判断item类型,然后处理
lonelydreamsym 2004-12-27
  • 打赏
  • 举报
回复
onitemcreated中处理
cyokin 2004-12-27
  • 打赏
  • 举报
回复
dataGrid 再客户端其实还是table阿
在 dataGrid_itemBound 或者dataGrid_databound(根据具体情况)
对每个 e.item(其实就是客户端的每一个td),itemBound或databound的时候是按行绑定的
你需要判断e.item的类型
如一下代码:
if (e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
然后根据dataGrid的值设置不同的颜色
如一下代码:
if (e.Item.Cells[11].Text=="1" && e.Item.Cells[2].Text!="*")
{
e.Item.Cells[3].CssClass=EscColor;
}
同时还能增加不同的事件
e.Item.Cells[4].Attributes["onclick"]=string.Format("ShowEditBox(1,'CheckShoteikinmucd','');");

再不明白 偶就没办法了 别说html里的table不熟悉阿
panxuegang 2004-12-27
  • 打赏
  • 举报
回复
在哪个控件的onmouseover上写啊?是datagrid吗?还是别的地方
cyokin 2004-12-27
  • 打赏
  • 举报
回复
在itembound的时候 对这个item增加属性 onmouseover onmouseout
downmoon 2004-12-27
  • 打赏
  • 举报
回复
<script language="javascript">
function doReturn(valID,valCode,valName,valObjectName)
{
var IDTextBoxName="txt"+valObjectName+"ID";
//var CodeTextBoxName="txt"+valObjectName+"Code";
var NameTextBoxName="txt"+valObjectName+"Name";
parent.self.opener.document.forms[0].elements[IDTextBoxName].value =valID;
//parent.self.opener.document.forms[0].elements[CodeTextBoxName].value =valCode;
var intIndex=valName.indexOf('(');
if(intIndex>0)
valName=valName.substring(0,intIndex);
parent.self.opener.document.forms[0].elements[NameTextBoxName].value =valName;
parent.self.opener.document.forms[0].submit();
parent.close();
}
function Close(valObjectName)
{
parent.close();
}
function SelectRow(row)
{
var oldRow;
var TR;

oldRow = window.document .all ("tbSelectedRow").value;
if (oldRow !=-1)
{
TR = window.document .all ("dgdDetail").rows[oldRow];
if(oldRow%2==1)
TR.style.backgroundColor='White';
else
TR.style.backgroundColor='WhiteSmoke';
TR.style.color='buttontext';
TR.style.cursor='default';
}

row += 1

TR = window.document .all ("dgdDetail").rows[row]

TR.style.backgroundColor='#5a9ea5';
TR.style.color='buttontext';
TR.style.cursor='default';

window.document .all ("tbSelectedRow").value = row ;
window.document.all("txtNameSelected").value =TR.cells[1].innerText;
window.document.all("txtIDSelected").value =TR.cells[0].innerText;



}
</script>


asp:textbox id="tbSelectedRow" runat="server" Width="0px">-1</asp:textbox><asp:textbox id="txtObjectName" runat="server" Width="0px"></asp:textbox><asp:textbox id="txtNameSelected" runat="server" Width="0px">0</asp:textbox><asp:textbox id="txtIDSelected" runat="server" Width="0px">0</asp:textbox><asp:textbox id="txtCodeSelected" runat="server" Width="0"></asp:textbox><INPUT id="btnOK" style="BORDER-RIGHT: #000033 2px inset; BORDER-TOP: #99ccff 2px outset; FONT-WEIGHT: bold; FONT-SIZE: 11px; BORDER-LEFT: #99ccff 2px outset; COLOR: #ffffff; BORDER-BOTTOM: #000033 2px inset; FONT-FAMILY: arial; BACKGROUND-COLOR: #6699cc"
onmousemover="doReturn(txtIDSelected.value,txtCodeSelected.value,txtNameSelected.value,txtObjectName.value)" type="button" value="确 定">
wszlcx6688 2004-12-27
  • 打赏
  • 举报
回复
用javascript设置一个鼠标事件,当over的时候color=你想要得颜色
cpp2017 2004-12-27
  • 打赏
  • 举报
回复
onmouseover="this.runtimeStyle.cssText='background-color:red'" onmouseout = "this.runtimeStyle.cssText =''"; ____________________________ (2004年12月27日 17时29分44秒)

62,243

社区成员

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

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

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

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