C# 将工具提示添加到CommandField ButtonType=";链接“;
我正在尝试向gridview上的命令按钮添加工具类型,但我有点卡住了 这是标记C# 将工具提示添加到CommandField ButtonType=";链接“;,c#,asp.net,gridview,C#,Asp.net,Gridview,我正在尝试向gridview上的命令按钮添加工具类型,但我有点卡住了 这是标记 <asp:CommandField ButtonType="Link" ShowEditButton="true" EditText="!" ShowDeleteButton="true" DeleteText="3" CancelText="O" ItemStyle-CssClass="View1 View2 View3" ItemStyle-Width="4
<asp:CommandField ButtonType="Link" ShowEditButton="true" EditText="!" ShowDeleteButton="true" DeleteText="3" CancelText="O" ItemStyle-CssClass="View1 View2 View3" ItemStyle-Width="45px" UpdateText="P">
<ControlStyle Font-Names="'WingDings 2'" ForeColor="Black" Font-Size="16px" />
</asp:CommandField>
当我在代码隐藏中断点并查看
e.Row.Cells
中的内容时,它是DataControlInkButton
的集合,但我似乎在文档中找不到对此的任何引用,以查看是否有工具提示可以设置。您可以在Gridview
的RowDataBound
上设置它
我正在共享我的一个实现的代码片段
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState.ToString() == "Alternate, Edit")
{
foreach (TableCell cell in e.Row.Cells)
{
if (e.Row.Cells.GetCellIndex(cell) == 4)
{
((System.Web.UI.WebControls.LinkButton)(e.Row.Cells[4].Controls[2])).ToolTip = "Tooltip goes here";
}
}
}
}
}
catch (Exception _e)
{
}
}
希望这有帮助。我看了一个@EdWindeking,但那是按钮类型是图像,而不是链接的地方谢谢。。。我有点傻,没有意识到DataControlLinkButton实际上是一个LinkButton:doh: