本文介绍了如何在鼠标悬停时在Gridview列中显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何在Gridview列中显示工具提示。 ============================== ====== 正在使用asp.net c#sqlServer2005。 i在数据库中有大量数据我在gridview中显示它的罚款。 i在Gridview中有一列名为Days。在这个专栏中,我有MTW Th FS Su 0. 所以当用户将鼠标指针保持在M上时它应该是星期一而且 T - 周二 W-周三 周四周四 F - 周五 S-周六 Su - 星期天 0 - 不可用。 请你帮我如何设置这个专栏的工具提示。 在一栏中我应该显示8个工具提示。 请帮忙谢谢。 protected void GridView1_RowDataBound( object sender,GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var MONTH_COLUMN_SELL = 8 ; // 请在此更改月份列单元格 e.Row.Cells [MONTH_COLUMN_SELL]。 ToolTip = getMonthName(e.Row.Cells [MONTH_COLUMN_SELL] .Text); } } private string getMonthName( string monthCode) { string monthName = 串 .Empty; switch (monthCode) { case M: monthName = Monday; break ; // 添加其他条件 } return monthName; } 这是另一种方法,你必须使用Template字段 < asp: TemplateField HeaderText = ClearanceNumber > < ItemTemplate > < asp:标签 ID = lblClearanceNumber runat = server 文字 =' <% #Eval( ClearanceNumber)%>' 工具提示 =' <% #Eval( ClearanceNumber )%>' > < / asp:标签 > < / ItemTemplate > < / asp:TemplateField > < asp:TemplateField HeaderText = 天 > < ItemTemplate > < asp:Label ID = lblDays runat = server 文字 =' <% #Eval( 天)%>' 工具提示 =' <%#getMonthName(Eval( Days))%> ;' > < / asp:标签 > < / ItemTemplate > < / asp:TemplateField > 代码背后 受保护 string getMonthName( string monthCode) { string monthName = string .Empty; switch (monthCode) { case M: monthName = Monday; break ; case T : monthName = Tuesday; break ; case W : monthName = Wednesday; break ; case Th : monthName = Thursday; break ; case F : monthName = Friday; break ; case S : monthName = Saturday; break ; case Su : monthName = Sunday; break ; // 添加其他条件 } return monthName; } 请检查此方法的范围是 protected 这些给你.. http://vinaysingh2507.blogspot.com/2012/07/how-to-show-gridview-as-tooltip-on.html [ ^ ] http://forums.asp.net/p/1819794/5047458.aspx/1?How+to+show+Gridview+as+a+tooltip+on + mouseover + + a + cell + of + gridview + in + asp + net + C + [ ^ ] 如何在鼠标悬停时在gridview行中显示工具提示文本? [ ^ ] 您好Ranjith 选择DataGridView的EditColumns属性。首先单击特定列,然后转到右侧窗格上的ToolTipText属性,最后编辑文本。 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 andT - TuesdayW- WednesdayTh-ThursdayF - FridayS- SaturdaySu - Sunday0 - 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. 解决方案 Try thisprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var MONTH_COLUMN_SELL = 8; // Please change your month column cell here e.Row.Cells[MONTH_COLUMN_SELL].ToolTip = getMonthName(e.Row.Cells[MONTH_COLUMN_SELL].Text); } } private string getMonthName(string monthCode) { string monthName = string.Empty; switch (monthCode) { case "M": monthName="Monday"; break; // add other condition as you like } return monthName; }Here is another method to do this, you have to modify your grid view binding way using Template field<asp:TemplateField HeaderText="ClearanceNumber"> <ItemTemplate> <asp:Label ID="lblClearanceNumber" runat="server" Text='<%# Eval("ClearanceNumber") %>' Tooltip='<%# Eval("ClearanceNumber") %>'> </asp:Label> </ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Days"> <ItemTemplate> <asp:Label ID="lblDays" runat="server" Text='<%# Eval("Days") %>' Tooltip='<%# getMonthName(Eval("Days")) %>'> </asp:Label> </ItemTemplate></asp:TemplateField>In code behindprotected string getMonthName(string monthCode) { string monthName = string.Empty; switch (monthCode) { case "M": monthName = "Monday"; break; case "T": monthName = "Tuesday"; break; case "W": monthName = "Wednesday"; break; case "Th": monthName = "Thursday"; break; case "F": monthName = "Friday"; break; case "S": monthName = "Saturday"; break; case "Su": monthName = "Sunday"; break; // add other condition as you like } return monthName; }please check this method scope is protectedThese for you..http://vinaysingh2507.blogspot.com/2012/07/how-to-show-gridview-as-tooltip-on.html[^]http://forums.asp.net/p/1819794/5047458.aspx/1?How+to+show+Gridview+as+a+tooltip+on+mouseover+of+a+cell+of+gridview+in+asp+net+C+[^]How to show tooltip text in gridview row on mouseover?[^]Hi RanjithChoose EditColumns property of DataGridView. First Click on particular column and then go to ToolTipText property on right side pane and finally edit your Text. 这篇关于如何在鼠标悬停时在Gridview列中显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-10 20:00