asp.net - 如何在asp.net的gridview内的asp boundfield datafield hedertext上设置工具提示?
问题描述
我有网格视图。有两个 BoundField.here 我想在 BoundField DataField HeaderText Topic上设置工具提示。
代码。
<asp:GridView ID="Dgvlist" runat="server" >
<Columns>
<asp:BoundField DataField="topic" HeaderText="Topic" />
<asp:BoundField DataField="question" HeaderText="Question" />
</Columns>
</asp:GridView>
有什么解决办法吗?
解决方案
在列上设置工具提示的常用方法有 3 种BoundField
:
1) 使用代码隐藏RowDataBound
事件
protected void Dgvlist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
e.Row.Cells[0].ToolTip = DataBinder.Eval(e.Row.DataItem, "Topic", string.Empty);
}
}
2) 使用代码隐藏RowCreated
事件
protected void Dgvlist_RowCreated(object sender, GridViewRowEventArgs e)
{
foreach (TableRow row in Dgvlist.Controls[0].Controls)
{
row.Cells[0].ToolTip = DataBinder.Eval(e.Row.DataItem, "Topic", string.Empty);
}
}
3) 转换为TemplateField
使用Label
控件
<asp:GridView ID="Dgvlist" runat="server" ...>
<Columns>
<asp:TemplateField HeaderText="Topic">
<asp:Label ID="TopicID" runat="server" Text='<%# Eval("topic") %>' ToolTip='<%# Eval("topic") %>'>
</asp:Label>
</asp:TemplateField>
<asp:BoundField DataField="question" HeaderText="Question" />
</Columns>
</asp:GridView>
实际实现取决于您使用的方法。
相关问题:
推荐阅读
- swift - SwiftUI:具有计时器样式的文本在提供的日期更改后不会更新
- reactjs - 反应,将状态作为道具传递的问题
- audio - 如何提取每个 wav 文件的第一秒?
- java - 应用程序关闭时我需要关闭通知
- c# - 清除不同表时,数据集中的表也已清除
- python - 在两个子进程之间使用管道的异步流处理数据
- javascript - react-native 渲染速度比从 firebase 加载数据要快得多
- discord.py - (discord.py) 有什么方法可以自动保存嵌入图像?
- spring-boot - 春季启动UUID转换器
- html - 使用 DomPortalOutlet 时不呈现自定义字体