“Update/Cancel” buttons don't appear in TemplateField Edit button

强颜欢笑 提交于 2019-12-04 09:47:49

The <asp:TemplateField> is used when you want to set your own-defined i.e. User-Defined content for each item in the GridView control.

The <asp:CommandField> is used when you want to use pre-defined command buttons to perform select, edit, or delete operations. Check MSDN here.

So, when your are using your own user-defined way for edit button, you also need to specify your custom content way for Update & Cancel button inside <EditItemTemplate> as :

<asp:TemplateField >            
<ItemTemplate> 
<asp:ImageButton ID="editButton" runat="server" CommandName="Edit" Text="Edit" 
     ToolTip="Edit" ImageUrl="images/pincel1.png" />  
</ItemTemplate>            
<EditItemTemplate>
<asp:ImageButton ID="BtnUpdate" runat="server" CommandName="Update" Text="Update" 
     OnClick="BtnUpdate_Click" ImageUrl="images/Update.png"/>
<asp:ImageButton ID="BtnCancel" runat="server" CommandName="Cancel" Text="Cancel" 
     OnClick="BtnCancel_Click" ImageUrl="images/Cancel.png"/>
</EditItemTemplate>        
</asp:TemplateField >

And just make sure, Only if you are again providing your Custom Implementation for Update & Cancel logic, you also define the onclick events for these two Update and Cancel buttons. Else remove the OnClick from markup of these buttons. [ BtnUpdate_Click & BtnCancel_Click here.]

I think since you've converted it to a TemplateField, all of the automatically-functioning stuff (like Update/Cancel buttons) has been disabled. I'm betting you'll need to add an <EditItemTemplate> with the Update and Cancel buttons, and hook them to the relevant commands using CommandName.

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