C#做的网站,想用上下键控制GridView行焦点的移动,大家帮下忙
C#做的网站,想用上下键控制GridView行焦点的移动,大家帮下忙 --------------------编程问答-------------------- 在GridView里使用上下箭头(小键盘旁边)来选择记录希望对楼主有帮助 --------------------编程问答-------------------- 在前台的页面加上JS脚本:如
<script type="text/javascript">
var currentRowId = 0;
function SelectRow()
{
if (event.keyCode == 40)
MarkRow(currentRowId+1);
else if (event.keyCode == 38)
MarkRow(currentRowId-1);
}
function MarkRow(rowId)
{
if (document.getElementById(rowId) == null)
return;
if (document.getElementById(currentRowId) != null )
document.getElementById(currentRowId).style.backgroundColor = '#ffffff';
currentRowId = rowId;
document.getElementById(rowId).style.backgroundColor = '#ff0000';
}
</script>
在后台添加一下index变量的声明,和在Gridview的RowDataBound绑定事件里写,如:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("id",index.ToString());
e.Row.Attributes.Add("onKeyDown", "SelectRow();");
e.Row.Attributes.Add("onClick", "MarkRow(" +index.ToString() + ");");
index++;
}
}
--------------------编程问答-------------------- 楼上不错 --------------------编程问答-------------------- 不错不错,顶一个 --------------------编程问答--------------------
index变量点具体,我是新手
补充:.NET技术 , ASP.NET