Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello hi frnds,

In my project i have gridview.

In that Gridview i have a columnName called Days in which we have fields as
M T W Th F S Su

when the users keeps the mouse on gridview cell it must show
M as Monday
T as Tuesday
W as Wednesday
etc...etc.

This is my code

C#
foreach (GridViewRow item in GridView1.Rows)
        {

C#
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";
            }
        }



Please can any body can give the perfect answer for this ?

Thanks.
Posted
Comments
[no name] 29-Apr-12 8:21am    
The perfect answer for what? You forgot to ask a question.
Ranjith Reddy CSE 29-Apr-12 8:40am    
Boss, I need Tool tip as M for Monday , T for Tuesday etc etc... Please help me.
Ranjith Reddy CSE 29-Apr-12 8:41am    
Please study the above code...u will understand
Mohamed Mitwalli 29-Apr-12 9:08am    
did it work with you ??
Ranjith Reddy CSE 30-Apr-12 3:34am    
No boss Problem

Better way to achive that is to use switch[^] command.
C#
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;


The same result, but more elegant ;)
 
Share this answer
 
Comments
Mohamed Mitwalli 5-May-12 10:51am    
Agree with you switch better than IF statement
Hi ,
Try this it will work with you
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string Days = e.Row.Cells[9].Text;
       if (Days == "M")
       {
           e.Row.Cells[9].ToolTip = "Monday";
       }
       else if (Days == "T")
       {
           e.Row.Cells[9].ToolTip = "Tuesday";
       }
       else if (Days == "W")
       {
           e.Row.Cells[9].ToolTip = "Wednesday";
       }
       else if (Days == "Th")
       {
           e.Row.Cells[9].ToolTip = "Thursday";
       }
       else if (Days == "F")
       {
           e.Row.Cells[9].ToolTip = "Friday";
       }
       else if (Days == "S")
       {
           e.Row.Cells[9].ToolTip = "Tuesday";
       }
       else if (Days == "Su")
       {
           e.Row.Cells[9].ToolTip = "Saturday";
       }
    }
}

Best Regards
M.Mitwalli
 
Share this answer
 
v2
Comments
Ranjith Reddy CSE 30-Apr-12 3:35am    
Error Generates with this code,,can u please suggest another code
Mohamed Mitwalli 30-Apr-12 13:17pm    
could you send me the error message
Syed SufiyanUddin 5-May-12 3:35am    
No Error But, It doesnt shows Tooltip when mouseover on the column of the cell.
Mohamed Mitwalli 5-May-12 10:50am    
Make break point and debug the code make sure cell take tooltip .

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