Thursday, March 17, 2011

VB.NET OnmouseOver GridView Rowcolor Change [With RowdataBound]

 //Open GridView RowDataBound Property

If e.Row.RowType = DataControlRowType.DataRow Then

            e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';this.style.backgroundColor='orangered'")
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
            e.Row.Attributes.Add("onclick", "window.open('Default3.aspx');")

        End If

//write on source code

  <asp:GridView ID="GridView2" OnRowDataBound="GridView2_RowDataBound" runat="server">

VB.NET OnmouseOver GridView Rowcolor Change [With CSS]

 //CSS Class Used to Highlight GridView Row

.rowStyle {
    background-color:#AAFFEE;
    cursor:pointer;
}

//VB.Net Code for GridView Highlight Row onmouseover

GridView1.DataSource = myDataSet
GridView1.DataBind() For Each rowItem As GridViewRow In GridView1.Rows
    rowItem.Attributes.Add("onmouseover", "javascript:this.className = 'rowStyle'")
    rowItem.Attributes.Add("onmouseout", "javascript:this.className = ''")
Next