如何在Asp.net Gridview专栏中显示工具提示。 [英] How to Display TOOL TIP in Asp.net Gridview Column.

查看:83
本文介绍了如何在Asp.net Gridview专栏中显示工具提示。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Gridview列中显示工具提示。

============================== ======





正在使用asp.net c#sqlServer2005。



i在数据库中有大量数据我在gridview中显示它的罚款。



i在Gridview中有一列名为Days。在这个专栏中,我有MTW Th FS Su 0.



所以当用户将鼠标指针保持在M上时它应该是星期一而且

T - 周二

W-周三

周四周四

F - 周五

S-周六

Su - 星期天

0 - 不可用。



请你帮我如何设置这个专栏的工具提示。



在一栏中我应该显示8个工具提示。



请帮忙谢谢。

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.

推荐答案

如何为OutSide设置Gridview而不是Inside Gridview。

为此,你需要有javascript onmousein& onmouseout为控制。在JS方法中,根据需要显示/隐藏放置在某处的div。此div将包含您要显示的文本。



您可以通过以下方式执行以下操作:

1.在鼠标悬停和放大器上注入Javascript功能;鼠标悬停在网格行中的链接。

2.使用JavaScript,当您将鼠标悬停在该行上时,显示包含所需详细信息的div(此处为图像)

3使用JavaScript,隐藏div onmouseout。





对于注入JS,你需要使用 RowDataBound 的GridView,类似于:

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);");
   }
}



显示网格单元格的div onmouseover 事件,

隐藏网格单元格的div onmoustout 事件。



放置相同的逻辑对于你想拥有它的任何/所有控件。



试试!


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!


其他方法是从代码背后。



如果您的gridview是一个模板,代码应该是这样的:



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>



GridView_RowDataBound 事件中,您可以获取显示每行数据库中日期的控件,如上面Sandeep所述。即


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.


这篇关于如何在Asp.net Gridview专栏中显示工具提示。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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