asp.net 設(shè)置GridView的選中行
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-27 22:44:32
asp.net 設(shè)置GridView的選中行
asp.net 設(shè)置GridView的選中行:<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.getElementB
導(dǎo)讀asp.net 設(shè)置GridView的選中行:<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.getElementB
<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++;
}
}
當點某行時,直接選中,然后移動方向鍵則切換不同的選中行; 如果直接按方向鍵,則從第一行開始標識
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
asp.net 設(shè)置GridView的選中行
asp.net 設(shè)置GridView的選中行:<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.getElementB