Reputation: 1446
I searched for an answer here in SO, but I couldn't find one.
I have a gridview like this one:
<asp:GridView ID="gdvSubEventos" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField HeaderText="Descrição" DataField="Descricao">
</asp:BoundField>
<asp:BoundField HeaderText="Data" DataField="data" DataFormatString="{0:dd/MM/yyyy}">
</asp:BoundField>
<asp:CommandField HeaderText="Opção" EditText="Editar" ShowEditButton="true">
</asp:CommandField>
</Columns>
</asp:GridView>
If the user clicks on edit, another form is opened (above of the grid, in the same page) for editing.
The problem is: When the user clicks on the edit button for the first time, everything works. But if he clicks on the edit button again, after the postback of the first edit, the row in the gridview becomes editable.
How can I always avoid edit mode on gridviews?
Upvotes: 2
Views: 2166
Reputation: 4591
If you use the button provided in the command field you will trigger the editing ability of the gridview and the gridview expects you will be using embedded editing. Without getting into too much detail all you should have to do at the bottom of the RowEditEvent is set gdvSubEventos.EditIndex = -1
this should take the gridview out of edit mode.
To avoid the gridview from ever entering editmode at all - disable edit in the command field then add an edit button to bring up your own form:
<asp:ButtonField>
to the column list In the GridView RowDataBound event
When you select this button it will trigger the button's CommandEvent, not the GridView, so you need the row index reference to grab the data you need from the Gridview to populate your fields.
Upvotes: 2