======千年难遇之datagrid选择行改变底色的问题。你千万别以为是 : e.Item.Attributes.Add("onclick", "this.style.backgroundColor='Gr

0956304127832708 2003-08-11 05:12:09
怎样实现当选择点击行改变色后,当我又选择了其它行时,刚才选择的行的底色消失
也就是在数据网格中只有选择的行是改变的颜色?????????????
一定要用e.Item.Attributes.Add("onclick", "this.style.backgroundColor='Gray';")实现,如何在中间夹杂javascript代码实现,请大侠赐教。(如果用按钮,复选框实现则要到后台执行代码
,晃动厉害,效率太差,这我能实现。千万不要发这样的代码过来。)
...全文
485 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞行石 2003-08-12
  • 打赏
  • 举报
回复
用上DataList就都解决了。
bqljb 2003-08-12
  • 打赏
  • 举报
回复
后台(xx.aspx.vb)写上:
Private Sub dgGrid_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgGrid.ItemCreated
Dim selectID As Integer '----selectID 所选中项的ID号
Dim selectRows As Integer '----selectRows 所选中项的行号
selectRows = e.Item.ItemIndex
If selectRows >= 0 Then
selectID = CInt(dgGrid.DataKeys(selectRows))
End If
e.Item.Attributes("style") = "cursor:hand"
e.Item.Attributes("OnClick") = "dgClick(" & selectID & "," & selectRows & ")"
End Sub

页中(xx.aspx)写上 javascript:
// 单击使 DataGrid 变色
var OldIndex=1;
function dgClick(selectID,selectRows)
{
//alert(event.srcElement.innerText)
if (selectRows == -1)
return false; // 选择表头或表尾无效
var curIndex;
curIndex=selectRows+1;
var objTr;
objTr="document.all['dgGrid'].rows(curIndex)"
if (eval(objTr).bgColor=='#ffff00')
{
eval(objTr).bgColor='';
}
else
{
eval(objTr).bgColor='#ffff00'; }

if (OldIndex!=curIndex)
{
document.all["dgGrid"].rows(OldIndex).bgColor=''
}
OldIndex=curIndex; // OldIndex记录当前点击的行号
}

对以上代码若有疑问再问我啦:)
tonghaibinfc 2003-08-12
  • 打赏
  • 举报
回复
好象不合你的要求

你的点击也不是datagrid真正的选择了这行,是在点击其他行时改变前一行的颜色,

up下
tonghaibinfc 2003-08-12
  • 打赏
  • 举报
回复
再加一个onmouseout,onmouseover

e.Item.Cells(i).Attributes.Add("onmouseover", "this.style.backgroundColor='Gray'")
e.Item.Cells(i).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Attributes.Add("onclick", "this.style.backgroundColor='Gray';")

'white'这个就可以是你点击前的颜色了
Rossetti 2003-08-12
  • 打赏
  • 举报
回复
SelectItemStyle
shang515 2003-08-11
  • 打赏
  • 举报
回复
做个例子:
<script language=javascript>
function doclick(tab)
{
if(event.srcElement.tagName!="TD") return;
if(tab.oldTr!=null)
tab.oldTr.style.backgroundColor="#ffffff";
tab.oldTr=event.srcElement.parentElement;
tab.oldTr.style.backgroundColor="#aaaaaa";
}
</script>
<table border=0 width=200 onclick="doclick(this)">
<tr><td style="border:1px solid #336600">第一行</td></tr>
<tr><td style="border:1px solid #336600">第二行</td></tr>
<tr><td style="border:1px solid #336600">第三行</td></tr>
<tr><td style="border:1px solid #336600">第四行</td></tr>
<tr><td style="border:1px solid #336600">第五行</td></tr>
</table>
0956304127832708 2003-08-11
  • 打赏
  • 举报
回复
如果觉得这问题简单,就用我说的做出来啊。e.Item.Attributes.Add("onclick", "this.style.backgroundColor='Gray';这里还加点代码啊")
2002pine 2003-08-11
  • 打赏
  • 举报
回复
题目很吓人,实际不过如此
guoyan19811021 2003-08-11
  • 打赏
  • 举报
回复
dim i as integer
dim count as integer =datagrid.items.count
for i=0 to count-1
datagrid.items(i).Attributes.Add("onMouseOver","Currentcolor=this.style.backgroundcolor;" "this.style.backgroundColor='Gray';")
datagrid.items(i).Attributes.Add("onMouseOut","this.style.backgroundColor=Currentcolor;")
next
0956304127832708 2003-08-11
  • 打赏
  • 举报
回复
一定要用e.Item.Attributes.Add("onclick", "this.style.backgroundColor='Gray';")
实现,在中间还加点语句。
nonepassby 2003-08-11
  • 打赏
  • 举报
回复
SelectItemStyle
0956304127832708 2003-08-11
  • 打赏
  • 举报
回复
此问题极为复杂,期待高手中的高手出现?

62,072

社区成员

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

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

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

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