【ASP.NET】GridView中實現光棒效果

在類別名稱GridView裡的RowCreated方法,加入以下程式碼(完整Code) :

 Protected Sub GridView1_RowCreated(...省略...) Handles GridView1.RowCreated
       
        If e.Row.RowType = DataControlRowType.DataRow Then
            '給予Row屬性加入 MouseOver 當滑鼠移到上面時、MouseOut 當滑鼠移開時所觸動的事件。
            '範例中 FFE789 顏色可自行定義
            e.Row.Attributes.Add("onmouseover", "javascript:oriColor=this.style.backgroundColor;this.style.backgroundColor='FFE789';")
            e.Row.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor=oriColor;")
        End If

 End Sub

範例效果如圖:

留言

這個網誌中的熱門文章

【ASP】日期轉換(西元<-->民國)

【VB】使用NPOI元件來匯出Excel--DataTableToExcel

【SQL】符號切割字串變成多欄