日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Gridview应用技巧——如何为行添加事件

發布時間:2023/12/1 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Gridview应用技巧——如何为行添加事件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Gridview應用技巧——如何為行添加事件收藏

下面的代碼實現了如何為Gridview添加鼠標經過、離開、單擊、雙擊的事件?

?

?protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
??????? {
??????????? e.Row.Attributes.Add("BorderColor ", "#d2d2d2");
??????????? e.Row.Style.Add("Height","8px");
??????????? e.Row.Style.Add("FontSize","8");
??????????? e.Row.Style.Add("VerticalAlign", "Middle");
???????????
??????????? if (e.Row.RowType == DataControlRowType.DataRow)
??????????? {
??????????????
??????????????? string SelectID = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();//((ClientList)(e.Row.DataItem)).ClientID;
??????????????? if (!String.IsNullOrEmpty(SelectID))
??????????????? {
??????????????????? //鼠標雙擊Row時的效果
??????????????????? e.Row.Attributes.Add("ondblclick", "javascript:window.location.href='"+(string)ViewState["Href"]+"?ID=" + SelectID+ "';");
??????????????????? //鼠標經過Row時的效果
??????????????????? e.Row.Attributes.Add("onmouseover", "this.classname=onColor2(this)");
??????????????????? //鼠標離開Row時的效果
??????????????????? e.Row.Attributes.Add("onmouseout", "this.classname=offColor2(this)");
??????????????????? //鼠標鍵Row時的效果
??????????????????? e.Row.Attributes.Add("onmousedown", "this.classname=downColor(this," + SelectID + ")");
??????????????? }
?????????????
??????????? }

}

下面是JavaScript方法

function onColor2(td)
{
//?td.style.backgroundColor="#c0c0c0";
//?td.style.fontWeight="bold";
//?td.style.fontStyle="italic";
?td.style.color="#0600FF";
}

function offColor2(td)
{
//?td.style.backgroundColor="";
//?td.style.fontWeight='';
//?td.style.fontStyle='';
?td.style.color='';
?//td.style.backgroundColor='';
}
function downColor(td,a)
{
//?td.style.backgroundColor="";
//?td.style.fontWeight='';
//?td.style.fontStyle='';
var?? rowindex?? =?? td.rowIndex;
?for(var?? i=1;i <td.parentElement.rows.length;i++)
?{
????????? if(i!=rowindex)
?????????? {

???????????????//當選中其它行時,要把另外所有行的背景色去掉
??????????????? td.parentElement.rows[i].style.color='';
??????????????? td.parentElement.rows[i].style.backgroundColor?? =?? '';
?????????? }
? }
??? document.getElementById("hid").value=a;
?td.style.color='#0600FF';
?td.style.backgroundColor='#FFDE59';
}

轉載于:https://www.cnblogs.com/wpf123/archive/2009/05/14/2347472.html

總結

以上是生活随笔為你收集整理的Gridview应用技巧——如何为行添加事件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。