Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NETGridview
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 12-Jan-13 21:59pm
Comments
Tharaka MTR at 13-Jan-13 4:03am
   
This question is a re-post.
Ranjith Reddy CSE at 13-Jan-13 4:58am
   
Sir, Still i didnt get the answer for this solution....Please help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Other way of doing this is from code behind.
 
If your gridview is a templeted one, code should be something like this:
 
<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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 540
1 Tadit Dash 305
2 Sergey Alexandrovich Kryukov 250
3 Peter Leow 190
4 OriginalGriff 148
0 Sergey Alexandrovich Kryukov 9,395
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid