我必须为我的 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 = " ";
((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/