Update data from Dynamics NAV using aspx GridView

ClausHamannClausHamann Member Posts: 80
edited 2011-11-18 in NAV Three Tier
Hi

I am trying to use a GridView on an aspx web page to view and update data from Dynamics NAV.

I have managed to get it working for displaying data how ever I get the below when I try to update the data via the GridView control.

This is what I have done.

1. I have exposed the Customer Card pages as a web service in form 810 – Web Service
2. Create a new ASP.NET web site using VS2008
3. Added a service reference to the web service using the following url: http://localhost:7047/DynamicsNAV/WS/Services - named the reference WebService
4. Created an aspx web page
5. Setup an object data source using the web service WebService.CustomerCard_Binding object. I have setup ReadMultiple as Select Method (all parameters is setup as Parameter source = None) and UpdateMultiple as Update Method (the wizard didn’t allow parameters to be setup for the Update Method).
6. Added a GridView that uses the object data source as data source. The grid view shows Key (as a hidden field), No and Name.

A this stage I got an “The request failed with HTTP status 401: Unauthorized.” Error when I ran the webpage. I then added the following code to the ObjDSWebService_ObjectCreating event of the object data source:

protected void ObjDSWebService_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
CustomerCard_Binding wsCustomerCard = new CustomerCard_Binding();

wsCustomerCard.Url = "http://localhost:7047/DynamicsNAV/WS/MyCompany/Page/CustomerCard";;
wsCustomerCard.UseDefaultCredentials = false;
wsCustomerCard.Credentials = new System.Net.NetworkCredential("user", "password");

e.ObjectInstance = wsCustomerCard;
}

When I run the web page now is shows the list of customers as expected.

I then made the following changes to the GridView on the web page to enable editing:
1. Change the ReadOnly property to True for the No. field
2. Populated Enable Editing
3. Saved the page and ran it.

The web page still shows the customer list and when I press Edit on a row it changed the row view to the edit view where I am able to update the Name of the customer however I get the below error when I select update:

Server Error in '/UpdateCustomer' Application.

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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) +41
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +462
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +907
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +704
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

Does anybody know if it is possible to use the GridView control to update records in NAV using web services and if yes, then how?

Thanks

Claus

Comments

  • Rikt-ItRikt-It Member Posts: 37
    Hi

    I have the same problem!!

    Regards
    Christer
    Stockholm/Sweden

    Keywords:
    GridView1_RowUpdating,
    GridView1_RowUpdated,
    ObjectDataSource1.UpdateParameters
    Regards
    Christer in Stockholm, Sweden
  • yukonyukon Member Posts: 361
    Hi All,

    Don't bind with objectdatasource when you bind the gird view or etc. You may need to bind by programmatic. We can bind with objdatasource but need to do some many things. I forgot it :lol:
    That's my suggestion.


    Regards,
    Yukon
    Make Simple & Easy
Sign In or Register to comment.