Click here to Skip to main content
15,881,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Display TOOL TIP in Gridview Column.
====================================


am working on asp.net c# sqlServer2005.

i have large amount of data in database i have displayed in gridview its fine.

i have one column in Gridview with name Days. In this column i have M T W Th F S Su 0.

so when the user keeps the mouse pointer on M it should Monday and
T - Tuesday
W- Wednesday
Th-Thursday
F - Friday
S- Saturday
Su - Sunday
0 - Not Available.

Please can u help me how to set tooltip for this column.

In one column i should display 8 tool tips.

Please help Thanks.
Posted
Comments
Tharaka MTR 13-Jan-13 4:03am    
This question is a re-post.
Ranjith Reddy CSE 13-Jan-13 4:58am    
Sir, Still i didnt get the answer for this solution....Please help.

how to set it for OutSide the Gridview not a Inside Gridview.
For this, you need to have javascript onmousein & onmouseout for the control. In the JS method, show/hide a div placed somewhere as per your need. This div will have text that you want to show.

You can do the following by:
1. Inject Javascript function on mousehover & mouseout of the link in a grid row.
2. Using JavaScript, show a div that contains the needed details(image here) when you hover your mouseover that row
3. Using JavaScript, hide the div onmouseout.


For injecting JS, you need to use RowDataBound of GridView, something like:
C#
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{ 
   DataControlRowType rtype = e.Row.RowType;  
   if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
       && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
       && rtype != DataControlRowType.Pager)  
   { 
      // Control specific
      TextBox tb = (TextBox)e.Row.FindControl("myTextBox");
      
      // Show div         
      tb.Attributes.Add("onmouseover", "ShowDiv(this);");
      //Hide div
      tb.Attributes.Add("onmouseover", "HideDiv(this);");
   }
}

Show the div onmouseover event of the grid cell, and
Hide the div onmoustout event of the grid cell.

Put the same logic for any/all controls that you want to have it.

Try!
 
Share this answer
 
Other way of doing this is from code behind.

If your gridview is a templeted one, code should be something like this:

XML
<asp:TemplateField HeaderText="Day">
<ItemTemplate>
<asp:Label ID="lblDay" runat="server" Text='<%# Bind("Days") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

In the GridView_RowDataBound event, you can get the control which displays the day from database for each row, as mentioned above by Sandeep. i.e
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           DataControlRowType rtype = e.Row.RowType;
           if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
               && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
               && rtype != DataControlRowType.Pager)
           {
               Label lbl = (Label)e.Row.FindControl("lblDay");
               switch (lbl.Text)
               {
                   case "M":
                      lbl.ToolTip = "Monday";
                      break;
                   case "T":
                       lbl.ToolTip ="Tuesday";break;

                  // So on for your remaining days.

                }


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900