asp.net 設(shè)置GridView的選中行
更新時間:2009年04月09日 18:35:40 作者:
當點某行時,直接選中,然后移動方向鍵則切換不同的選中行; 如果直接按方向鍵,則從第一行開始標識
<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>
然后在gridview的rowDataBound中, 添加處理按鍵的事件處理函數(shù)和使用鼠標點擊某行時的選中事件.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("id", _i.ToString());
e.Row.Attributes.Add("onKeyDown", "SelectRow();");
e.Row.Attributes.Add("onClick", "MarkRow(" + _i.ToString() + ");");
_i++;
}
}
當點某行時,直接選中,然后移動方向鍵則切換不同的選中行; 如果直接按方向鍵,則從第一行開始標識
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>
然后在gridview的rowDataBound中, 添加處理按鍵的事件處理函數(shù)和使用鼠標點擊某行時的選中事件.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("id", _i.ToString());
e.Row.Attributes.Add("onKeyDown", "SelectRow();");
e.Row.Attributes.Add("onClick", "MarkRow(" + _i.ToString() + ");");
_i++;
}
}
當點某行時,直接選中,然后移動方向鍵則切換不同的選中行; 如果直接按方向鍵,則從第一行開始標識
您可能感興趣的文章:
相關(guān)文章
使用 .NET MAUI 開發(fā) ChatGPT 客戶端的流程
最近?chatgpt?很火,由于網(wǎng)頁版本限制了 ip,還得必須開代理,用起來比較麻煩,所以我嘗試用 maui 開發(fā)一個聊天小應(yīng)用,結(jié)合 chatgpt 的開放 api 來實現(xiàn),這篇文章主要介紹了使用 .NET MAUI 開發(fā) ChatGPT 客戶端,需要的朋友可以參考下2022-12-12
asp.net 下拉列表無級數(shù)據(jù)綁定實現(xiàn)代碼
asp.net 下拉列表無級數(shù)據(jù)綁定實現(xiàn)代碼,需要的朋友可以參考下。2010-10-10
asp.net 使用Response.Filter 過濾非法詞匯
一般信息發(fā)布網(wǎng)站,論壇等均具有實現(xiàn)非法詞匯過濾功能,即當用戶錄入非法詞匯時,進行替換,使其無法顯示到頁面上,針對此種功能,通常采用的時,在讀取時,在讀到非法詞匯后,進行替換。2010-03-03
使用asp.net mvc,boostrap及knockout.js開發(fā)微信自定義菜單編輯工具(推薦)
這篇文章主要介紹了使用asp.net mvc,boostrap及knockout.js開發(fā)微信自定義菜單編輯工具,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-05-05
c# 讀取Northwind數(shù)據(jù)庫image字段
我在寫一個三層結(jié)構(gòu)Demo時,使用了Northwind這個范例數(shù)據(jù)庫。但是奇怪的是,讀取Categories表的Picture列(image類型)無法在image控件中正常顯示(解決方案在后面代碼中可以看到)。2009-03-03
asp.net c# 調(diào)用百度pai實現(xiàn)在線翻譯,英文轉(zhuǎn)中文
本文詳細介紹asp.net c# 調(diào)用百度pai 實現(xiàn)在線翻譯以及英文轉(zhuǎn)中文實現(xiàn)代碼,需要了解的朋友可以參考下2012-12-12

