0

I have a long-term project (approx 9 years of continual use so far) that uses gridviews in several pages. The gridviews are used to display abbreviated summary details only, each with separate editing forms (hidden until called) being used.

I'm not using in-grid editing as the editing is too complex. The editing form is called and revealed either by the separate Add button or by a row's Edit linkbutton (using a ButtonField).

This approach has worked perfectly for several years upto and including .net 3.5. However, after a recent attempt to upgrade the project platform to .net 4 I found the grids entered in-line edit mode when:

  1. The gridview Edit link button is clicked, and then
  2. The edit form is dismissed by either the cancel button or save button methods

The gridview does not enter the editmode until after the actual editing form is dismissed. If the Save method is invoked, then a full re-bind of the gridview is involved, but it still enters editmode!

I have tried setting the grid's EditIndex to -1, but this doesn't make any difference.

If I reset the compilation target to 3.5 the grids all behave as expected again. I don't have this problem with projects originally started as .net 4 projects.

Partial UI code:

<asp:Button ID="cmdAdd" runat="server" Text=" Add " />
<asp:GridView ID="gvWPHA" runat="server" AutoGenerateColumns="false" 
DataKeyNames="PORLID" AllowSorting="false"
EmptyDataText="No records yet" EmptyDataRowStyle-CssClass="qansYes">
<HeaderStyle CssClass="gvhead" />
<RowStyle CssClass="TRPrime" />
<AlternatingRowStyle CssClass="TRAlt" />
<SelectedRowStyle CssClass="TRSelect" />
<Columns>
    <asp:ButtonField ButtonType="Link" Text="Edit" CommandName="Edit" />
    <asp:BoundField DataField="PORLID" HeaderText="Record #" />
    <asp:BoundField DataField="DateOfAppt" SortExpression="DateOfAppt" HeaderText="Appt Date" DataFormatString="{0:dd/MM/yyyy}" />
    <asp:BoundField DataField="OutcomeDesc" HeaderText="Outcome" />
    <asp:ButtonField ButtonType="Link" Text="Delete" CommandName="Delete" />
      </Columns>
</asp:GridView>


<asp:UpdatePanel ID="upEdit" runat="server">
 <ContentTemplate>
   ... Editing Form markup and validation, cancel button, save button, etc ...
 </ContentTemplate>
</asp:UpdatePanel>

Has anyone else experienced this problem?

Adrian
  • 5,603
  • 8
  • 53
  • 85

1 Answers1

1

There was a change in the GridView's behavior in .NET 4.0. The Microsoft Connect bug report is here: https://connect.microsoft.com/VisualStudio/feedback/details/554166/gridview-sets-editindex-property-when-in-previous-net-versions-it-didnt

Jared Shaver
  • 1,339
  • 8
  • 12