Click here to Skip to main content
16,010,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello hi frnds,

In my project i have gridview. I need TOOL tip on Mouse Over.

In that Gridview i have a columnName called DAYS in which i have

DAYS
=================
M T W Th F S Su

when the users keeps the mouse on gridview cell, it must show Tool tip as :

M as Monday
T as Tuesday
W as Wednesday
Th as Thursday
F as Friday
S as Saturday
Su as Sunday


This is my code

C#
foreach (GridViewRow item in GridView1.Rows)
        {
 Collapse | Copy Code
string Days = item.Cells[9].Text;

            Days = Days.Substring(0, 1);
            if (Days == "M")
            {
                item.Cells[9].ToolTip = "Monday";
            }
            else if (Days == "T")
            {
                item.Cells[9].ToolTip = "Tuesday";
            }
        }


But these code unable to work out.

Please can anyone help me. am Trying Since from 1 week.

Thanks,
Posted
Comments
[no name] 6-May-12 11:32am    
Reason for my vote of 1
Asked and answered twice already. No effort made to debug. No mention of error.

Hi ,
Make sure you are putting this code RowDataBound
www.codeproject.com/Answers/375432/Gridview-Cells-Tool-tip-Text[^]

And Put break point and debug the code .

Best Regards
M.Mitwalli
 
Share this answer
 
The RowDataBound event of the GridView can be used to setup the ToolTips as follows:

C#
//Create an array of Day Names
string[] dayNames = Enum.GetNames(typeof(DayOfWeek));

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
    if (e.Row.RowType == DataControlRowType.DataRow) {
        string day = e.Row.Cells[9].Text;
        e.Row.Cells[9].ToolTip = dayNames.FirstOrDefault(n => n.StartsWith(day == "T" ? "Tu" : day == "S" ? "Sa" : day)) ?? "";
    }
}
 
Share this answer
 
v2
Comments
Ranjith Reddy CSE 6-May-12 3:19am    
Sorry, unable to work this code
VJ Reddy 6-May-12 3:21am    
Put a break point in the RowDataBound method and step through the code to see the problem.
Mohamed Mitwalli 6-May-12 3:40am    
5+
VJ Reddy 6-May-12 4:00am    
Thank you.
Espen Harlinn 7-May-12 10:40am    
5'ed!
 
Share this answer
 
Comments
Ranjith Reddy CSE 6-May-12 2:02am    
Unable to work out with ur code
Mohamed Mitwalli 6-May-12 3:40am    
5+

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