GridView inside FormView cannot get into Edit Mode

Discussion in 'ASP .Net' started by Don, Jan 25, 2008.

  1. Don

    Don Guest

    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">
    <Columns>
    <asp:BoundField DataField="WorkorderActionID" /
    >

    <asp:CommandField ShowEditButton="True" />
    </Columns>
    </asp:GridView>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:FormView>
     
    Don, Jan 25, 2008
    #1
    1. Advertising

  2. Don

    Lanoli

    Joined:
    Sep 26, 2008
    Messages:
    2
    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: Sep 26, 2008
    Lanoli, Sep 26, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. OS538DAV
    Replies:
    0
    Views:
    891
    OS538DAV
    Nov 22, 2006
  2. =?Utf-8?B?QWRhciBXZXNsZXk=?=

    GridView not entering Line Editing mode when inside FormView

    =?Utf-8?B?QWRhciBXZXNsZXk=?=, May 10, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    527
    Steven Cheng[MSFT]
    May 28, 2007
  3. dba56
    Replies:
    0
    Views:
    674
    dba56
    Jan 16, 2008
  4. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    401
    Jaime Stuardo
    Apr 7, 2006
  5. jobs at webdos
    Replies:
    0
    Views:
    478
    jobs at webdos
    Oct 9, 2006
Loading...

Share This Page