Jerry的专栏

QQ: 26010284 MSN: cuijian1900@hotmail.com

原创 当鼠标移动时,改变datagrid中的颜色收藏

新一篇: english Web about .net | 旧一篇: 生成dll编译我的组件

<script runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)
        BindGrid()
    End Sub
   
    Sub BindGrid()
        Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ColtAtAspAlliance"))
        Dim myDataAdpater As New SqlDataAdapter("Select Top 10 * from Colt_Products", myConnection)
        Dim myDataSet As DataSet
   
        Try
            myDataSet = New DataSet()
   
         '----------------------------------
         ' Fill the DataSet for the DataBinding of the 2 DataGrid
         '----------------------------------
         myDataAdpater.Fill(myDataSet)
   
            DataGrid1.DataSource = myDataSet
            DataGrid1.DataBind()
   
            DataGrid2.DataSource = myDataSet
            DataGrid2.DataBind()
   
        Catch SQLEx As SqlException : Response.Write(SQLEx.Message.ToString())
        Catch Ex As Exception : Response.Write(Ex.Message.ToString())
        End Try
    End Sub
   
    Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
   
        If e.Item.ItemType = ListItemType.Item Or _
            e.Item.ItemType = ListItemType.AlternatingItem Then
   
         '---------------------------------------------------
         ' Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
         '---------------------------------------------------
         e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
   
        End If
   
    End Sub
   
    Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
   
        If e.Item.ItemType = ListItemType.Item Or _
            e.Item.ItemType = ListItemType.AlternatingItem Then
   
         '---------------------------------------------------
         ' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
         '---------------------------------------------------
         e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
            e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
   
         '---------------------------------------------------
         ' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
         ' (Or you may do it for a whole Row of DataGrid :)
         '---------------------------------------------------
         e.Item.Cells(3).Style("cursor") = "hand"
   
         '---------------------------------------------------
         ' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
         '---------------------------------------------------
         e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
   
        End If
    End Sub

</script>

发表于 @ 2004年09月07日 10:16:00|评论(loading...)|编辑

新一篇: english Web about .net | 旧一篇: 生成dll编译我的组件

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © ppoo