Gridview单元格工具提示文本 [英] Gridview Cells Tool tip Text

查看:61
本文介绍了Gridview单元格工具提示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,朋友们,

在我的项目中,我有gridview.

在该Gridview中,我有一个名为Days的columnName,其中的字段为
M T W Th F S Su

当用户将鼠标放在gridview单元上时,它必须显示
M为星期一
T表示星期二
W为星期三
等...

这是我的代码

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

foreach (GridViewRow item in GridView1.Rows)
        {


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.

推荐答案


试试这个,它会和你一起工作
Hi ,
Try this it will work with you
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";
       }
    }
}


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


更好的实现方法是使用 ^ ]命令.
Better way to achive that is to use switch[^] command.
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 ;)


这篇关于Gridview单元格工具提示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆