Answered by:
How can a linkbutton between ItemTemplate be visible in edit mode?

Question
-
User-427368358 posted
Hi
I try to understand this situation:
a gridview has a linkbutton (delete) between ItemTemplates only (no EditItemTemplate). There is nothing in code-behind about that linkbutton. There is also a commandfield.
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="ann" runat="server" CausesValidation="false" OnClientClick="return confirm('OK?');" CommandName="Delete" >
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField><asp:CommandField ShowEditButton="True" CausesValidation="false"/>
In normal mode, the delete and the edit button are of course visible. When i click on the edit button, i still see the delete button for that row beside the update and the cancel button. How come? I would rather expect not to see the delete button in edit mode.
Thanks
Raf
Wednesday, November 25, 2020 9:36 AM
Answers
-
User-427368358 posted
Well, you finally gave me the explanation. it took a while but we got there: the ItemTemplate is always displayed in that case.
And your solution works too. No need for code-behind.
Sometimes you have to persevere ...
Thanks- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 25, 2020 2:28 PM
All replies
-
User475983607 posted
I try to understand this situation:
a gridview has a linkbutton (delete) between ItemTemplates only (no EditItemTemplate). There is nothing in code-behind about that linkbutton. There is also a commandfield.
If I understand your problem statement, the you created a template column but only included the ItemTemplate. There's no EditItemTemplate. In this situation, the ItemTempate is always displayed. This allows you to control what fields within the row are editable.
One solution is adding an empty EditItemTemplate or adding an EditItemTemplate with an empty label.
<asp:TemplateField HeaderText="Delete"> <ItemTemplate> <asp:LinkButton ID="ann" runat="server" CausesValidation="false" OnClientClick="return confirm('OK?');" CommandName="Delete" Text="Delete" > </asp:LinkButton> </ItemTemplate> <EditItemTemplate> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:CommandField HeaderText="Command" ShowEditButton="True" CausesValidation="false" />
Wednesday, November 25, 2020 1:25 PM -
User-427368358 posted
Well, you finally gave me the explanation. it took a while but we got there: the ItemTemplate is always displayed in that case.
And your solution works too. No need for code-behind.
Sometimes you have to persevere ...
Thanks- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 25, 2020 2:28 PM -
User475983607 posted
Well, you finally gave me the explanation. it took a while but we got there: the ItemTemplate is always displayed in that case.It took a while because of the "Cargo Cult Programming" style. It's unusual to create separate command button columns. A typical GridView design has one command button column where the buttons are dynamically displayed. Anyway, that's the default behavior.
Wednesday, November 25, 2020 3:35 PM -
User-427368358 posted
I understand. Not always easy to admit that we were wrong
Thursday, November 26, 2020 8:50 AM