Link to home
Start Free TrialLog in
Avatar of Contestoas
ContestoasFlag for Norway

asked on

Gridview, objectdatasource update error message

Hello

I'm having a hard time figuring out a problem I have been stuck with for two days now.
I'm developing a web project which contains a gridview, that should have a edit/update function.

First off I have have a method that returns a datatable that varies in size from time to time. Getting data from different database tables.
This method is the select method for the datasource, and it works fine.

Then I've added a Command field: Edit, Update, Cancel to the gridview and created a simple test update method that just change the text of a label on the page.
Added this update method to the datasource, but just cant get this to work.
On the datasource, the DataObjectTypeName is set to: System.Web.UI.WebControls.GridViewRow

When I click on the update link, the following error message is produced:
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

I haven't really worked that much with gridviews and datasources, but how does the update method get the correct row, the one that are being edited?
And I guess this is related to my problem?

Regards
Marius

My code:

//Update method
public void UpdateGridView(GridViewRow test)
{
            Label1.Text = "Updated! ";           
}
 
//The gridview and datasource
<asp:GridView ID="gwSelectedForm" runat="server" DataSourceID="ObjectDataSource1" 
        onrowcreated="gwSelectedForm_RowCreated" 
        onrowupdating="gwSelectedForm_RowUpdating">
    <Columns>
        <asp:CommandField ShowEditButton="True" />
    </Columns>
</asp:GridView>
 
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    SelectMethod="SetGridView" TypeName="LookupEdit.Home" 
    DataObjectTypeName="System.Web.UI.WebControls.GridViewRow" 
    UpdateMethod="UpdateGridView">
    <SelectParameters>
        <asp:ControlParameter ControlID="ddlFormAccess" DefaultValue="" Name="lookup" 
            PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

Open in new window

SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Contestoas

ASKER

Hi
Thank you for answering.

My problem is that the parameters for the update is not always the same.
It can vary for each time. Thats why I trie to send in the row.
Is there a way to check how many parameters there is, and create them on the fly?

I've added the primary key to the DataKeyValues in the gridview.

Still I dont understand why the error message is produced.

Regards
Marius
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So it all comes down to that I simply just can't send the gridviewrow in as a parameter?
Is there maybe a way to override the objectDataSource update method?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
all this help is great, I understand now better how the ObjectDataSource/GridView works.
But I still dont understand why I get the error message.
I have a constructor in my class:
public Home()
{
}
I might add that the class is a public partial class Home : System.Web.UI.Page.
But I've also tried connecting the datasource to a Test.cs class with the same methods, and I get the same error message.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, I now understand why the error occures.
I'm programming up against an API which have methods that will handle the update, so I just need to get the changed values.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, I guess so :(
Anyway, thanks for all your help people:)

Regards
Marius