GridView inside FormView cannot get into Edit Mode
am 25.01.2008 15:08:40 von chambersdonI 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/microsoft.public.dotnet.frame work.aspnet/browse_frm/thread/4a738593c506a359/5182c2fd489c9 292?hl=en&lnk=st&q=onRowEditing+objectDataSource+mode#5182c2 fd489c9292
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
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:
TypeName="RIPData.WorkOrder.WorkOrders">
AutoGenerateColumns="False" CellPadding="4"
DataSource='<%# Eval("Actions") %>'
ForeColor="#333333" GridLines="None"
OnRowEditing="gvActionRecords_OnRowEditing">