how to add a tooltip and confirm message box to asp CommandField(image button)

情到浓时终转凉″ 提交于 2019-12-11 04:53:53

问题


     <asp:GridView ID="GridView1" runat="server" 
                        AllowPaging="True" AllowSorting="True"
                        DataMember="DefaultView" 
                        DataSourceID="SqlDataSource1"...
     >
     <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField ...

                            <asp:CommandField  ButtonType="Image" DeleteText="Delete" ShowDeleteButton="True" DeleteImageUrl="images/deletered1.png"></asp:CommandField>                               
                        </Columns>                    
                        <FooterStyle BackColor="#507CD1" .../>
                    </asp:GridView>

I have a grid view with a an <asp:CommandField> in every row but I can't find a prperty to set a tooltip text("delete") or confirm message box (something like "Are you sure?" Yes No)


回答1:


Try converting your CommandField to a TemplateField, like this:

<asp:TemplateField HeaderText="Delete">
    <ItemTemplate>
        <asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
            OnClientClick="return confirm('Are you sure you want to delete this user?');" />
</ItemTemplate>
</asp:TemplateField>

Then you just need to handle your Command in code-behind.



来源:https://stackoverflow.com/questions/18133902/how-to-add-a-tooltip-and-confirm-message-box-to-asp-commandfieldimage-button

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