﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Mon, 21 Jun 2010 05:53:41 GMT</pubDate><dc:creator>Glayaar</dc:creator><description>&lt;p&gt;I assume you are talking about the workaround where the DataKeyField of the parent table is hidden. For such scenario, you will need to manually insert the parent key value into the HTML child table new row cell during BeginRowEditing client side event handler.&lt;/p&gt;&lt;p&gt;THe snippet provide below assume the parent table is named CustomerObj while the child table is named OrderObj. The parent key is located on the second column of the child table.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;In order to correctly retrieve the parent key value from the child table, you will need to modify the AddPendingChanges client side event handler into:&lt;/p&gt;&lt;pre&gt;function WebGrid1_OnAddPendingChanges(controlId, table, rowChange)&lt;br /&gt;{&lt;br /&gt;    var grid = ISGetObject(controlId);&lt;br /&gt;&lt;br /&gt;    if (table.Name == "CustomerObj")&lt;br /&gt;    {&lt;br /&gt;        setTimeout(function ()&lt;br /&gt;        {&lt;br /&gt;            //debugger;&lt;br /&gt;            rowChange.Element.setAttribute("KeyValue", idTemp);&lt;br /&gt;            rowChange.KeyValues = idTemp &amp;#43; "";&lt;br /&gt;            rowChange.Row.KeyValue = idTemp &amp;#43; "";&lt;br /&gt;            idTemp&amp;#43;&amp;#43;;&lt;br /&gt;        }, 10);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;Here is the snippet for BeginRowEditing client side event handler:   &lt;/p&gt;&lt;pre&gt;function WebGrid1_OnBeginRowEditing(controlId, row)&lt;br /&gt;{&lt;br /&gt;    var grid = ISGetObject(controlId);&lt;br /&gt;&lt;br /&gt;    if (row.Type == "NewRow" &amp;amp;&amp;amp; row.Table.Name == "OrderObj")&lt;br /&gt;    {&lt;br /&gt;        var cells = row.GetElement().getElementsByTagName("td");&lt;br /&gt;        var idx = 0;&lt;br /&gt;&lt;br /&gt;        for (var i = 0; i &amp;lt; cells.length; i&amp;#43;&amp;#43;)&lt;br /&gt;        {&lt;br /&gt;            if(cells[i].getAttribute("type") == "Cell")&lt;br /&gt;            {&lt;br /&gt;                if (idx == 1)&lt;br /&gt;                {&lt;br /&gt;                    var parentKey = row.GetParentRow().KeyValue;&lt;br /&gt;                    cells[i].innerHTML = parentKey;&lt;br /&gt;                    cells[i].setAttribute("cellValue", parentKey);&lt;br /&gt;                    break;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                idx&amp;#43;&amp;#43;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Sun, 20 Jun 2010 02:56:26 GMT</pubDate><dc:creator>huzzy143</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks the solution did work perfectly, but i have a little problem here.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In Herarchical grid which is bound to List&amp;lt;&amp;gt; Custom object, when i add a new row in the parent table then the script is run and new keyValue is given to the new row. now when i am trying to add a new row inside this newly created row in Hierarchical grid then the ParentId is coming as 0 and not the new KeyValue given to parent record.&lt;/p&gt;
&lt;p&gt;This way when the batchUpdate is been processed then i get error as parentId with 0 is not found.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Can you please tell me how to overcome this situation.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Huzefa&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Tue, 15 Jun 2010 06:24:28 GMT</pubDate><dc:creator>Glayaar</dc:creator><description>&lt;p&gt;A developer have another suggestion for the scenario you are facing, you could use the AddPendingRow client side event handler in order to insert the row KeyValue to the RowChange object if you wish to hide the primary key cell. However during the BatchUpdate server side event, you will need to retrieve the primary key from the KeyValue property instead of the cell since the cell is hiddden. Here is the snippet for the AddPendingRow client side event handler:&lt;/p&gt;&lt;pre&gt;function wgTest_OnAddPendingChanges(controlId, table, rowChange)&lt;br /&gt;{&lt;br /&gt;    var grid = ISGetObject(controlId);&lt;br /&gt;&lt;br /&gt;    setTimeout(function()&lt;br /&gt;    {&lt;br /&gt;        rowChange.KeyValues = idTemp &amp;#43; "";&lt;br /&gt;        idTemp&amp;#43;&amp;#43;;&lt;br /&gt;    }, 10);   &lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Assuming the idTemp is the latest ID count you retrieved from the database.&lt;/p&gt;
&lt;p&gt;The snippet to retrieve the primary key during server side event handler is, assuming the added row is in index 0 in the pending changes object:&lt;/p&gt;&lt;pre&gt;((ISNet.WebUI.WebGrid.WebGridRowChanges)e.PendingChanges[0]).KeyValue&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Mon, 14 Jun 2010 00:15:06 GMT</pubDate><dc:creator>Glayaar</dc:creator><description>&lt;p&gt;You could try using the OnEndRowEditing client side event handler in order to modify the newly added cell primary key field using the SetText and SetValue function. You will also need to be able to retrieve the latest incremental value of the primary key in the clietn side (perhaps using hidden HTML input to store the value from database). Attached is a simple demonstration of the suggestion, for this sample the incremental value is set to 10.&lt;/p&gt;&lt;p&gt;The primary key column must be shown in the WebGrid in order to invoke the SetText and SetValue function. If we hide it using the visible property the cell object in the OnEndRowEditing event handler will return null. As a workaround, you could set the column EditType to NoEdit as demonstrated in the sample. &lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Sun, 13 Jun 2010 02:03:05 GMT</pubDate><dc:creator>huzzy143</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Is there no way i can manually handle the Auto-Increment of DatKeyField through javascript??&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Huzefa&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Thu, 10 Jun 2010 16:20:30 GMT</pubDate><dc:creator>handy@intersoftpt.com</dc:creator><description>&lt;p&gt;Hi Huzefa,&lt;/p&gt;&lt;p&gt;It is not our WebGrid that is not supporting this. It is List&amp;lt;&amp;gt; binding itself that is not fully supporting for auto-increment scenario. &lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Handy&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Thu, 10 Jun 2010 02:37:29 GMT</pubDate><dc:creator>huzzy143</dc:creator><description>&lt;p&gt;Hi Handy,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I will explain my application archtecture a bit first:&lt;/p&gt;
&lt;p&gt;In my application UI is seperated from Business Components. The UI contains dispay related logic whereas the Business Component contains Business related logic. So the UI doesn't know anything about the database except that it recieves data in form of DTO (data transfer object) which is like a set of class containing subclasses to show dependencies.&lt;/p&gt;
&lt;p&gt;Now i cannot use your DataSource controls as i don't directly connect to database. Thats why I directly bind List&amp;lt;&amp;gt; object to WebGrid.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Now to use the batch update feature i need to have an Id field which should always Auto-Increment(as asking user to put in Id wouldn't be great). &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Once the user has added, updated or deleted any row in the WebGrid and wants to save the changes to database then on batchupdate event i again make a List&amp;lt;&amp;gt; object to be passed to Business Component. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The user should be able to Add, Update or Delete in Bulk for which the Auto-Increment of DataKeyField is very important.&lt;/p&gt;
&lt;p&gt;But you say that Auto-Increment for List&amp;lt;&amp;gt; object Field is not properly supported in WebGrid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So will it be never be supported or you guys working on resolving it?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Can i have an Auto-Increment field which won't be bound to List&amp;lt;&amp;gt; but is seperate and work as DataKeyField? In this case it doesn't have to understand the List&amp;lt;&amp;gt; object.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Huzefa&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Mon, 10 May 2010 00:03:40 GMT</pubDate><dc:creator>handy@intersoftpt.com</dc:creator><description>&lt;p&gt;Hi Huzefa,&lt;/p&gt;&lt;p&gt;Based on the sample you sent me before, I could not replicate the issue. It runs well when I add and delete the added rows. So, would you mind to show me step by step to replicate the issue? e.g in recording video.&lt;br /&gt;&lt;br /&gt;I think List binding can cause the issue because it is not suppossed in autoincrement scenario.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Handy&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Sat, 08 May 2010 02:25:03 GMT</pubDate><dc:creator>huzzy143</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;What about Situation 2, I dont wanna show the Auto Increment column to user. Instead hide it from user but internally it should keep auto incrementing.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Making the Auto Increment to Visible=false is giving problem as mentioned in my earlier post. Please tell me how can i overcome it?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Huzefa&lt;/p&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Thu, 06 May 2010 23:28:49 GMT</pubDate><dc:creator>handy@intersoftpt.com</dc:creator><description>&lt;p&gt;Hello Huzefa,&lt;/p&gt;&lt;p&gt;As far I know, List binding does not have auto increment feature. So the ID property is just a simple number property, which doesn't know about any logics. The ID return incorrectly from List itself. If you look into our sample, when we don't handle identity, the ID would always return incorrect ID, until you refresh the grid. HowEver, we can retrieve it back from database but List or the data itself not.&lt;/p&gt;
&lt;p&gt;Currently, you could not hide Accept all changes button. If you don't show the statusbar, it will raise an error for batch update scenario. The possible way is hide the element, such as the code below:&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;function WebGrid1_OnInitialize(controlId) {
            var WebGrid1 = ISGetObject(controlId);       
            document.getElementById("dvStatus_WebGrid1").style.display = "none";
            return true;
}
&lt;/pre&gt;
&lt;p&gt;Regards,&lt;br /&gt;Handy&lt;/p&gt;
&lt;p /&gt;</description></item><item><title>AutoIncrement of KeyField giving problem when record already exists</title><link>http://www.intersoftsolutions.com/Community/WebGrid/AutoIncrement-of-KeyField-giving-problem-when-record-already-exists/</link><pubDate>Wed, 05 May 2010 09:38:11 GMT</pubDate><dc:creator>huzzy143</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I want to use the Batch Update functionality for Web Grid. For this i set the DataKeyField of RootTable.Columns and add a column with DataMember of DataKeyField, and set its AutoIncrement property to true.&lt;/p&gt;
&lt;p&gt;I allow user to Add,Update or Delete any record in the grid. Everything works great when there is no data in the grid.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;But suppose if there are any existing records in the grid, It gives a problem.&lt;/p&gt;
&lt;p&gt;The AutoIncrement column always starts its counter from 0, irrespective of data that already exists in that field.&lt;/p&gt;
&lt;p&gt;Suppose i have set DataKeyField to "Id" Column.. Here's the structure&lt;/p&gt;
&lt;p&gt;Id             FirstName                  LastName&lt;/p&gt;
&lt;p&gt;1                John                             Doe&lt;/p&gt;
&lt;p&gt;2                Tim                              Brooklin&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;This record comes up in the grid once i open the page, now when i add a new record the new record is given the Id of 0, Now again i enter second new record its given an id of 1 by Auto Increment column.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;If you see the Id 1 already existed in grid that was rendered in first page load and after that i enter 2 new records i get the same id of 1, which is a big problem..&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Why is it happening so, why is the AutoIncrement not taking into picture the existing records and generate the new id based on the highest value of that column.&lt;/p&gt;
&lt;p&gt;I dont want to update the database every time when a new record is entered, I want to update the database only when the user has finished updating the whole grid data.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;How can i accomplish this?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Huzefa&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>