Monday, August 17, 2009

Display Message On MouseOver In an ASP.NET GridView

To display a message in an ASP.NET GridView on MouseOver, handle the RowDataBound event. As given in MSDN,

The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.





SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]">






DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True"

OnRowDataBound="GridView1_RowDataBound">



















C#


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if ( e.Row.RowType == DataControlRowType.DataRow )

{

e.Row.Attributes.Add("onmouseover", "alert('Display some message');");

}

}



VB.NET


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

If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Attributes.Add("onmouseover", "alert('Display some message');")

End If

End Sub

No comments:

Post a Comment