Tooltip in different ways

Tool tip option can be enabled without doing coding in the code behind.

In ASPX

<asp:templatefield>
<itemtemplate>
<asp:label runat=”server”
text='<%# Eval ( “ProductID” ) %>’
tooltip='<%# Eval ( “ProductDescription” ) %>’ />
</itemtemplate>
</asp:templatefield>

In code behind – Model: 1

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
‘ Assumes target cell is in column 2 and the underlying data item is sDistrictName

If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Cells(2).Attributes.Add(“Title”, e.Row.DataItem(“sDistrictName”).ToString)

End If

End Sub

In Code Behind – Model: 2

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

{

e.Row.Cells[4].ToolTip = “No Status”;

}

In Code Behind – Model: 3

This is a special case if you need to change the tool tip based on Data Field

string sDay = e.Row.Cells[9].Text;
string sName = String.Empty;
           switch (sDay)
           {
               case "M":
                   sName = "Monday";
                   break;
               case "T":
                   sName = "Tuesday";
                   break;
               case "W":
                   sName = "Wednesday";
                   break;
               case "Th":
                   sName = "Thursday";
                   break;
               case "F":
                   sName = "Friday";
                   break;
               case "S":
                   sName = "Tuesday";
                   break;
               case "Su":
                   sName = "Saturday";
                   break;
           }
           e.Row.Cells[9].ToolTip = sName;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s