iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi,
I’ve WebGrid, and defined BindingOperationMode="ClientBinding" AllowAddNew="Yes". Also set DataSourceType="WebService".
I’ve this code for the insert function in the webservice:
private TransactionResult InsertMembershipTypePrice(MembershipTypePrice newObject, int nPriceType) { Medcan.Business.MembershipTypePrice price = new Medcan.Business.MembershipTypePrice(); price.MembershipTypeID = newObject.MembershipTypeID; price.IsActive = newObject.IsActive; price.EffectiveDate = newObject.EffectiveDate; price.EndDate = newObject.EndDate; price.Description = newObject.Description; price.PriceFlag = nPriceType; price.MemberCategory = GetComboConfigID(newObject.MemberCategoryName, "MembershipCategory"); Decimal nTemp = 0; Decimal.TryParse(newObject.MemberPrice, out nTemp); price.MemberPrice = nTemp; using (TransactionScope scope = new TransactionScope()) { price.Save(); newObject.MembershipTypePriceID = price.MembershipTypePriceID; scope.Complete(); } MembershipDataContext context = new MembershipDataContext(); return new TransactionResult() { OperationType = DataSourceOperation.Insert, ReturnValue = true, AffectedResults = newObject.MembershipTypePriceID }; }
How can the grid recognize the new added row key value, like when I add a new record in the database, how can I pass back the new row key value to the grid?
Thanks,
Maged Mikaeel
The WebGrid development team stated that this feature will be implemented in the next build version of WebGrid. I will send you the nightly build of the hotfix when the pre-release hotfix is ready to be evaluated.
Edited on November 12, 2012 8:30 PMReason: Update Latest Status of Task #974
WebGrid development team has managed to implement the feature.
I'd like to introduce the "NewID" property of TransactionResult object. For your scenario, we need to set the value of NewID to the ID of the inserted object.
Below is the snippet code of InsertMethod in my WebService.
[WebMethod] public TransactionResult InsertShipper(Shipper newObject) { NorthwindDataContext context = new NorthwindDataContext(); WebGridDataProvider<Shipper> provider = new WebGridDataProvider<Shipper>(context.Shippers.AsQueryable()); TransactionResult tresult = provider.Insert(newObject); tresult.NewID = newObject.ShipperID; return tresult; }
This insert method will insert Shipper object. I'm using Shippers table of Northwind database in my simple sample. The table has ShipperID as the primary key and it is incremental primary key.
After invoke the Insert(newObject) method, simply set the NewID property of the TransactionResult object and then return this object.
There are points that need to be done in the WebGrid:
<ISWebGrid:WebGrid ID="WebGrid2" runat="server" ...> <LayoutSettings ...> </LayoutSettings> <RootTable DataKeyField="ShipperID"> <Columns> ... </Columns> </RootTable> <ClientBindingSettings DataSourceType="WebService" ServiceUrl="WebService.asmx" ItemTypeName="Shipper"> <ServiceMethods SelectMethod="GetShippers" InsertMethod="InsertShipper" /> </ClientBindingSettings> </ISWebGrid:WebGrid>
<Columns> <ISWebGrid:WebGridColumn Caption="ShipperID" DataMember="ShipperID" DataType="System.Int32" Name="ShipperID" Width="100px" EditType="NoEdit" DefaultValue="-1" IsAutoIncrement="true"> </ISWebGrid:WebGridColumn> ... </Columns>
I have sent you a message to your registered email account. The message contains the link to download the nightly build of the hotfix and step by step to apply them manually.
I have tested in a simple sample and found no problem so far. Please have the nightly build hotfix tested on your end and let us hear your feedback.
Any update please?
Hi there,
Just wondering when are you planning to post back the answer as I'm waiting for your answer/
Maged
I’m currently still investigating this issue and need more time to provide you with solution, suggestion, or sample.
I’ll get back to you as soon as possible.
In common scenario, WebGrid will automatically recognize the new added row key value.
We have a walkthrough topic, Walkthrough: Configuring client-binding using WebService mode, that can be used as reference for your specific scenario. Below is the sample snippet code for the insert function in the WebService.
[WebMethod] public TransactionResult InsertCustomer(Customer newObject) { NorthwindDataContext context = new NorthwindDataContext(); WebGridDataProvider<Customer> provider = new WebGridDataProvider<Customer>(context.Customers.AsQueryable()); return provider.Insert(newObject); }
Could you please provide us with more detail information regarding your scenario such as: does the key value using GUID or incremental number?
Hope this helps.
Thanks for your reply.
1- I use incremental number for the key value.
2- The main different between my code and your sample, is:
on your sample you used this to create the record in the database:
return provider.Insert(newObject);
and you returned back the result, which I don't know what it has internally!
on my code, I used this line of code to create the object.
price.Save();
The save function will create a new record in the database and give me back the new generated record with the new key generated by the database engine.
Then I used this code to create the return object:
MembershipDataContext context = new MembershipDataContext(); return new TransactionResult() { OperationType = DataSourceOperation.Insert, ReturnValue = true, AffectedResults = newObject.MembershipTypePriceID };
Now, how can I simulate or correctly create the return object that inform the grid with the new record key value?
Any update?
Sorry for the late respond.
Since you are using auto-increment number for the key value, you will need to handle the select identity during insert operation in the WebMethod.
Please let me know your response.
I don't know what you mean with that!!
I can get the new key after the inster function which is fine, but how can I send this value back to the grid after I finish the insert operation? This is my question for you.
Like in this line of code I return TransactionResult object
How can we include the new key value to this return object?
Currently there is no field that can be used as container to keep the TransactionResult. We have plan to implement the “new key” field along with the property tag.
Should you need to have a property or variable to accommodate the TransactionResult, please create a new class that inherits TransactionResult class and then add a new property to keep the result.
Please let us know your response.
In case I create the inherited class and added a new field for the new key, how can I attach the new key to the added row in the grid?
Deeply sorry for the late respond.
Regarding the new ID on auto-increment column, it is possible to create a workaround but will require extensive coding. WebGrid development team has considered to implement the automatic ID mapping feature in this release.
Was this addressed yet? If yes can you give me an example of how to use it?
This feature request is already queued in our work items, Task #974.When the hotfix is ready, I’ll surely let you know and give you an example about how to use it.
Is this task (Task #974.) was done?
Task #974 has not been completed yet.I will let keep you informed with any news I heard from the team regarding task #974.
Any update?!
The status of Task #974 is on progress. When the nightly build of the hotfix is ready, I will let you know.
Any update?!!
Its now over a year and NO fixe yet!! Can't belive you can't fix such issue!!
I apologized for any inconvenience this problem may have caused you. Your feature request is already queued in our work items. I may be able to help raising the priority for your feature request.
I’ll let you know any update I heard from the team regarding Task #974.
I gave up on you guys, to be really honest, you have fantastic looking UI and also functionality, BUT you also have too many unnecessary issues and many perfromance issues, these problems really delay my development and also almost no fix for any issues I raised to you guys. I think I will have to switch to another UI without that much of issues, mostly Dev Express will do the job without these problems and issues.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname