2014年3月7日 星期五

gridview72絕技之一-螢光棒效果DataControlRowType

前台-必須加上OnRowDataBound="GridView1_RowDataBound

   <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" 
            Font-Bold="True" Font-Size="Medium" PageSize="12" Width="1200px" 
            DataKeyNames="uid" OnRowDataBound="GridView1_RowDataBound">


=======================================================================
後台

  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        Dim i As Integer

        For i = 0 To GridView1.Rows.Count - 1

            If e.Row.RowType = DataControlRowType.DataRow Then

                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#CEFF63'")

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c")
            End If
        Next
    End Sub





沒有留言:

張貼留言