日期:2014-05-19  浏览次数:20450 次

如何让gridview中的select得到焦点?
<asp:GridView   ID= "GridView1 "   DataSourceID= "ObjectDataSource1 "   DataKeyNames= "UserCode "   AutoGenerateSelectButton= "True ">
aspx页面中这样写,绑定发生后会自动产生select键,我想让绑定生成select键后再按下回车就选中这个值(每次绑定后只会有一行结果),怎么做啊??

------解决方案--------------------
给你一个可以参考的实现方法(当鼠标放到gridview中的某一数据行的时候改变该行的背景色)

1.编写javascript
var _oldColor;
function SetNewColor(source)
{
_oldColor = source.style.backgroundColor;
source.style.backgroundColor = '#fefbd2 ';
}
function SetOldColor(source)
{
source.style.backgroundColor = _oldColor;
}


2.在后台代码绑定javascript
Gridview1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//绑定javascript,
e.Row.Attributes.Add( "onMouseOver ", "SetNewColor(this); ");
e.Row.Attributes.Add( "onMouseOut ", "SetOldColor(this); ");
}
}

------解决方案--------------------
你的需求我没有做过,不过你看看上面的代码应该有参考的地方的
------解决方案--------------------
楼上的还没有选中的效果的话, function GridRowMouseOver(str)
{
if (document.all[ "dgData "].children[0].children[Math.round(str)].className != "GridRow01 ")
{document.all[ "dgData "].children[0].children[Math.round(str)].className= "GridRow00 ";}
}
function GridRowMouseOut(str)
{
if (document.all[ "dgData "].children[0].children[Math.round(str)].className != "GridRow01 ")
{document.all[ "dgData "].children[0].children[Math.round(str)].className= "td_dark ";}
}
function ShowBugDesc(strItemIndex,strBugDesc)
{ var i ;
i=0;
var obj=document.all[ "dgData "].children[0];
var max=obj.children.length;
for (i=1;i&lt;max;i++)
{
if (obj.children[i].className!= "td_dark ")
{
obj.children[i].className= "td_dark ";
}
}

obj.children[Math.round(strItemIndex)+1].className= "GridRow01 ";

}


也就是点中一行的时候, 让这行变颜色, 实际上是假的选中,
------解决方案--------------------
设置Form.AcceptButton属性 为你要默认回车的那个Button 就行了