Tooltip not displaying in IE 8, Chrome, FF for gridview command field update, cancel buttons in ASP.Net

[亡魂溺海] 提交于 2019-12-12 01:48:02

问题


My gridview consists of a command field with 'showedit' button property set to true. All functionalites are working fine except that tooltip is not displaying for the autogenerated update and cancel buttons, instead it displays tooltip as 'edit' itself which is the tooltip for 'edit' button. It is displaying correctly in IE compatibility view but not in IE 8 or Chrome or FF browsers!. I searched in net, most solutions suggested to use template field instead of command field, my problem is at this stage implementing template field will result in lot of code changes. Please suggest whether this is possible in Command field itself! The gridview design code is given below:

<asp:CommandField ButtonType="Image" ShowEditButton="True" ValidationGroup="EditAnswer" CancelImageUrl="../images/Cancel.jpg" CancelText="Click to cancel" UpdateImageUrl="../images/Update.jpg" UpdateText="Click to save this answer" EditImageUrl="../images/Edit.jpg" EditText="Click to edit this answer">              <ControlStyle CssClass="para1" />                                                      <ItemStyle HorizontalAlign="Center" Width="10%" />                             </asp:CommandField>

I tried setting tooltip for autogenerated update and cancel buttons also but this also failed because I am not able to get the controls for update and cancel buttons in row databound event.


回答1:


I have implemented this functionality using command field itself in gridview's row databound event,

    if (e.Row.RowType == DataControlRowType.DataRow)
    {            
        e.Row.Cells[2].ToolTip = "Click to Edit answer";
        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) == 2)
                {
                    ((System.Web.UI.WebControls.ImageButton)(e.Row.Cells[2].Controls[0])).ToolTip = "Click to update answer";
                    ((System.Web.UI.LiteralControl)(e.Row.Cells[2].Controls[1])).Text = "&nbsp;";
                    ((System.Web.UI.WebControls.ImageButton)(e.Row.Cells[2].Controls[2])).ToolTip = "Click to cancel answer";
                }
                i++;
            }
        }
    }

This code works fine in all browsers!



来源:https://stackoverflow.com/questions/7357124/tooltip-not-displaying-in-ie-8-chrome-ff-for-gridview-command-field-update-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!