GridView inside FormView cannot get into Edit Mode

D

Don

I have a GridView inside a FormView and cannot get it into editMode.
The FormView is bound to an ObjectDataSource. One of the fields
returned by the ObjectDataSource is a List which I bind to the
GridView. In the GridView I have a field bound to the items in this
list.

If I click edit at runtime with this setup I get an error message that
says: "The GridView 'gvActionRecords' fired event RowEditing which
wasn't handled".
So, I have to handle this RowEditing event. In the event handler I
set the GridView's EditIndex value to the NewEditIndex in the
GridViewEditEventArgs variable. Once I do this I can get into edit
mode but I'm always one postback behind. I click edit on the 1st row
and nothing happens. I click Edit on the second row and the first
rows goes into edit mode. And so on...

I've tried reBinding the FormView after I set the Index and it does
nothing. I never get into edit mode, not even one postback behind.
I cannot reBind just the DataGrid because I get a run time error:
"Databinding methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

I found a posting that is very close to this problem. Their solution
is to create a private class variable and set it to the EditIndex
variable in the RowEditing event. Then, during page Render set the
GridView's EditIndex to this private variable. I did this but then I
never get into edit mode (not even one step behind).

Here is a link to that post:

http://groups.google.com/group/micr...diting+objectDataSource+mode#5182c2fd489c9292

This is what my page does, and the code is below.
The ObjectDataSource has a SelectMethod which calls getWorkorder and
returns a class called WorkOrder.
This WorkOrder class has a Property called Actions which is a strongly
typed List<T>. My GridView is bound to this property using this
statement DataSource='<%# Eval("Actions") %>' .

The list returned by the Actions property contains a class which has a
property called WorkorderActionID that I bind to a BoundColumn in the
DataGrid.

Here is the page:

<asp:ObjectDataSource ID="odsWorkorders" runat="server"
SelectMethod="getWorkorder"
TypeName="RIPData.WorkOrder.WorkOrders">
<SelectParameters>
<asp:parameter Name="workorderNumber" Type="String" />
<asp:parameter Name="tailNumber" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:FormView ID="FormView1" runat="server"
DataSourceID="odsWorkorders">
<ItemTemplate>
<table align="left">
<tr>
<td><asp:Label ID="Label2" runat="server" Text="Workorder
Number:" SkinID="label"></asp:Label></td>
</tr>
<tr>
<td>
<asp:GridView ID="gvActionRecords" runat="server"
ShowHeader=False
AutoGenerateColumns="False" CellPadding="4"
DataSource='<%# Eval("Actions") %>'
ForeColor="#333333" GridLines="None"
OnRowEditing="gvActionRecords_OnRowEditing">
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
 
Joined
Sep 26, 2008
Messages
2
Reaction score
0
Symptoms are:
* The update handler isn't raised when updating a row.
* On the autogenerated edit column the "update" button will have commandName "edit" instead of "update"
* Any events raised from controls in edit templates will not be raised (since the gridview isn't in edit mode after postback)

The gridview in a formview behaves weird due to the editindex being wrong after postback. This can be fixed easily by implementing the viewstate for the gridview edit index like:
Code:
 Private Property PreviousGridEditIndex() As Integer
        Get
            If ViewState("PreviousEditIndex") Is Nothing Then
                ViewState("PreviousEditIndex") = -1
            End If
            Return CInt(ViewState("PreviousEditIndex"))
        End Get
        Set(ByVal value As Integer)
            ViewState("PreviousEditIndex") = value
        End Set
    End Property

    Protected Overrides Function SaveViewState() As Object
        PreviousGridEditIndex = Me.DataGridEigendom_r.EditIndex
        Return MyBase.SaveViewState()
    End Function

    Protected Overrides Sub LoadViewState(ByVal savedState As Object)
        MyBase.LoadViewState(savedState)
        Me.DataGridEigendom_r.EditIndex = PreviousGridEditIndex
    End Sub
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top