asp.net - 如何为 Commandfield ButtonType 添加工具提示作为图像

标签 asp.net css

我必须为我的 gridview 编辑图像按钮添加工具提示。我编码为 Commandfield。

<asp:CommandField ButtonType="Image"  
    HeaderStyle-HorizontalAlign="center"
    EditText="Edit" UpdateText="Edit" 
    ShowEditButton="True"  
    ItemStyle-VerticalAlign="Top"
    EditImageUrl="~/Images/edit.png"    
    UpdateImageUrl ="~/Images/Save.png" CancelImageUrl ="~/Images/cancel.png" 
    ItemStyle-Width="15px" ControlStyle-Width="15px">
</asp:CommandField>

是否可以在 gridview 命令字段按钮类型中添加工具提示作为图像?

最佳答案

以下代码效果很好:

protected void gvResourceEditor_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    e.Row.Cells[4].ToolTip = "Edit Resource Details";
                    if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState.ToString() == "Alternate, Edit")
                    {
                        int i = 0;
                        foreach (TableCell cell in e.Row.Cells)
                        {
                            if (e.Row.Cells.GetCellIndex(cell) == 4)
                            {
                                ((System.Web.UI.WebControls.ImageButton)(e.Row.Cells[4].Controls[0])).ToolTip = "Update Resource Details";
                                ((System.Web.UI.LiteralControl)(e.Row.Cells[4].Controls[1])).Text = "&nbsp;";
                                ((System.Web.UI.WebControls.ImageButton)(e.Row.Cells[4].Controls[2])).ToolTip = "Close Resource Details";
                            }
                            i++;
                        }
                    }
                }
            }
            catch (Exception _e)
            {
            }
        }

关于asp.net - 如何为 Commandfield ButtonType 添加工具提示作为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16035699/

相关文章:

asp.net - IIS ARR - 反向代理的 URL 重写 - 如何发送 HTTP_HOST

c# - MVC 5 路由属性

html - 使子div占据最大高度

c# - ASP.NET MVC : How to default to a page given certain condition?

c# - 如何使用 Web 处理程序创建 PDF?

javascript - 将页面的一部分(圆形按钮/PNG)固定在 JQuery Mobile 页面上的最佳方法?

CSS - 无法获取单个 li 元素以在悬停时显示 div

html - using::before 在元素下添加阴影

javascript - 如何在文本输入字段中添加逗号来分隔每组三位数字?

c# - 缓存和线程安全