GridView Row Tooltip hover

Posted on: Tue Apr 21 11:21:55 -0700 2009. Updated on: Tue Apr 21 11:27:31 -0700 2009.
Category: DotNet

This is a neat trick to get a tooltip when a user hovers over a row in a gridview. It is very simple and uses standards.

Simply attach something like this to the GridView's RowDataBound event:

protected void GridViewEligibleProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      // get the row view to be able to access data from the binding object
      DataRowView drv = (DataRowView)e.Row.DataItem;
      // lets me type safe, optional
      ProductsSvc.DSProducts.AgencyEligibleProductsRow thisRow = (ProductsSvc.DSProducts.AgencyEligibleProductsRow)drv.Row;
      // this is the magic to get the tooltip. You could put anything as the 2nd parameter
      e.Row.Attributes.Add("title", (thisRow.IsdescriptionNull() ? "" : thisRow.description));
   }
}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.