以下範例說明如何mouse經過Gridview某一列,會顯示光棒
首先在aspx加入style
..
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.normal
{
background-color:white;
}
.highlight
{
background-color:#cccccc;
}
</style>
..
</head>
.cs 在gridview 事件RowCreated加入以下code
Protected Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowCreated
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Attributes.Add("onmouseover", "this.className='highlight'")
e.Row.Attributes.Add("onmouseout", "this.className='normal'")
End If
End Sub
加入測試資料
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ShowGridData()
End Sub
Sub ShowGridData()
Dim lst As List(Of Bus) = New List(Of Bus)()
lst.Add(New Bus With {.ID = 1, .Name = "板橋線"})
lst.Add(New Bus With {.ID = 2, .Name = "土城線"})
lst.Add(New Bus With {.ID = 3, .Name = "新埔線"})
lst.Add(New Bus With {.ID = 4, .Name = "中和線"})
GridView1.DataSource = lst
GridView1.DataBind()
End Sub
'....
End Class
'資料類別
Public Class Bus
Private _id As Integer
Private _name As String
Public Property ID() As Integer
Get
Return _id
End Get
Set(value As Integer)
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(value As String)
_name = value
End Set
End Property
End Class
沒有留言:
張貼留言