(一). 樣本圖片
(二). 代碼
[前台]
<script language="javascript">
function DbClickEvent(d)
{
window.alert("事件類型: DoubleClidk 作用對象: " + d);
}
function ClickEvent(d)
{
window.alert("事件類型: OnClick 作用對象: " + d);
}
function GridViewItemKeyDownEvent(d)
{
window.alert("事件類型: GridViewItemKeyDownEvent 作用對象: " + d);
}
function KeyDownEvent()
{
if( event.altKey && event.keyCode > 48 && event.keyCode < 54 )
{
window.alert("事件類型: FormKeyDownEvent 選中記錄數: " + ( parseInt(event.keyCode) - 48 ));
}
}
</script>
[後台]
if( e.Row.RowType == DataControlRowType.DataRow)
{
//滑鼠移動到每項時顏色交替效果
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
//單擊/雙擊 事件
e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[1].Text + "')");
e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')");
e.Row.Attributes.Add("OnKeyDown", "GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')");
//設定懸浮滑鼠指標形狀為"小手"
e.Row.Attributes["style"] = "Cursor:hand";
}
* 關於事件,不僅僅就這些, 還有更多, 用類似方法可以完成更複雜,效果更佳的頁面.
(三). 範例程式碼下載
http://files.cnblogs.com/ChengKing/Gridview(DBclick%20OnmouseOver%20etc).rar