Friday, January 7, 2011

Highlight grid view row on mouse over

Subject : Highlight grid view row on mouse over
For that you have to add attribute  mouserover and mouseout of Gridview row.

You can assign this attribute on OnRowDataBound
Event of gridview.

Code Snippet:
.aspx code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    
DataSourceID="SqlDataSource1" OnRowDataBound="bound" BackColor="Silver"
    
onselectedindexchanged="GridView1_SelectedIndexChanged"  >
    <Columns>
        <asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
        <asp:BoundField DataField="empolyeeno" HeaderText="empolyeeno"
             
SortExpression="empolyeeno" />
        <asp:BoundField DataField="location" HeaderText="location"
             
SortExpression="location" />
        <asp:BoundField DataField="position" HeaderText="position"
             
SortExpression="position" />
    </Columns>
</asp:GridView>

.apx.cs code
    Protected void bound(object sender, GridViewRowEventArgs e)
    {
         e.Row.Attributes.Add("onmouseover", "style.backgroundColor='#ffffff'");
        e.Row.Attributes.Add("onmouseout", "style.backgroundColor='#C0C0C0'");
       
        
    }

No comments:

Post a Comment