Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't GridView perform update function on being databinded to an ObjectDataSource?
    primarykey
    data
    text
    <p>I followed this <a href="http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control,-part-1-getting-started" rel="nofollow noreferrer">awesome tutorial</a> when I needed to get kickstarted with ASP.NET! Accordingly, I started making a web app for a store! I started to code to store an ItemGroup which contains just two properties Name and Remark,both String! Entity Framework has been used. The validation code has been performed with the use of DataAnnotation as follow -</p> <pre><code>namespace StoreAppWeb.DAL { [MetadataType(typeof(ItemGroupMetaData))] public partial class ItemGroup { } public class ItemGroupMetaData { [StringLength(50, ErrorMessage = "Name of Item Group must be 100 characters or less.")] [Required(ErrorMessage = "Name of Item Group is missing!")] public string Name { get; set; } } } </code></pre> <p>Realizing the importance of Persistence Ignorance, DAL and BLL has been implemented via the repository pattern. Then, the ItemGroupMgmtPage has been created whose main purpose is to add, delete and update the ItemGroup! Databinding though ObjectDataSource has been used. Everything works fine except the 'Updating' action! The portion of the code that really concerned here are posted here. The portion of ItemGroupBL class that really concerns here is -</p> <pre><code>namespace StoreAppWeb.BLL { public class ItemGroupBL : IDisposable { private bool disposedValue = false; private IItemGroupRepository itemGroupRepository; public ItemGroupBL() { this.itemGroupRepository = new ItemGroupRepository(); } //Other Functionality methods went here public void UpdateItemGroup(ItemGroup itemGroup, ItemGroup origItemGroup) { if(!itemGroup.Name.Equals(origItemGroup.Name)) validateSingleItemGroup(itemGroup); try { itemGroupRepository.UpdateItemGroup(itemGroup, origItemGroup); } catch(Exception ex) { throw ex; } } private void validateSingleItemGroup(ItemGroup itemGroup) { var duplicateItemGroup = itemGroupRepository.GetItemGroupByName(itemGroup.Name); if (duplicateItemGroup != null) { throw new DuplicateItemGroupException(String.Format("ItemGroup {0} already exists!", itemGroup.Name)); } } } } </code></pre> <p>And the portion of the ItemGroupMgmtPage that really concerned here is given as -</p> <pre><code>&lt;h2&gt; Edit the Available Item Group List: &lt;/h2&gt; &lt;asp:ObjectDataSource ID="ItemGroupObjectDataSourceForInsert" runat="server" TypeName="StoreAppWeb.BLL.ItemGroupBL" DataObjectTypeName="StoreAppWeb.DAL.ItemGroup" SelectMethod="GetItemGroups" UpdateMethod="UpdateItemGroup" DeleteMethod="DeleteItemGroup" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="orig{0}"&gt; &lt;/asp:ObjectDataSource&gt; &lt;asp:GridView ID="GridViewItemGroupEdit" runat="server" AutoGenerateColumns="False" DataSourceID="ItemGroupObjectDataSourceForInsert" DataKeyNames="ID" AllowPaging="True" AllowSorting="true" OnRowDataBound="GridViewItemGroupEdit_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:CommandField ShowEditButton="true" ShowDeleteButton="true" /&gt; &lt;asp:DynamicField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-VerticalAlign="Top" /&gt; &lt;asp:DynamicField DataField="Remark" HeaderText="Remark" SortExpression="Remark" ItemStyle-VerticalAlign="Top" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:ValidationSummary ID="ItemGroupValidationSummary" runat="server" ShowSummary="true" DisplayMode="BulletList" /&gt; </code></pre> <p>I am unable to perform the update but rather get this -</p> <p><img src="https://i.stack.imgur.com/YX5dn.png" alt="enter image description here"></p> <p>Any clue why?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload