Deleting with C1GridView and EntityDataSource

Posted by: kaytea on 10 September 2017, 11:41 am EST

  • Posted 10 September 2017, 11:41 am EST

    Hi,
    I encountered a problem when deleting an item in C1GridView that is bound to an EntityDataSource. The error is "Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object"

    Data Relations:
    - Categories: catID (PK, Guid), catName (varchar), sysName (FK to SystemNames table, varchar)
    - SystemNames: sysName (PK, varchar).

    EntityDataSource:
    <asp:EntityDataSource ID="CategoriesDS" runat="server" ContextTypeName="xxxxx.MyEntities"
    ConnectionString="name=MyEntities" DefaultContainerName="MyEntities"
    EntitySetName="Categories" EnableFlattening="False" OrderBy="it.[catName]"
    EnableDelete="true" EnableInsert="true" EnableUpdate="true" >
    </asp:EntityDataSource>



    Grid:
    <cc1:C1GridView ID="gvC1Categories" runat="server" AutoGenerateColumns="False" AllowSorting="true"
    DataKeyNames="catID" DataSourceID="CategoriesDS" Visible="false" VisualStyle="Office2007Silver"
    UseEmbeddedVisualStyles="true" OnRowEditing="gvC1Categories_RowEditing" OnRowUpdating="gvC1Categories_RowUpdating"
    OnRowDeleting="gvC1Categories_RowDeleting" OnRowDeleted="gvC1Categories_RowDeleted">
    <PagerSettings Position="Top" Mode="NumericFirstLast" PageButtonCount="5" />
    <Columns>
    <cc1:C1TemplateField>
    <ItemTemplate>
     
    <asp:ImageButton ImageUrl="~/img/edit.gif" ID="EditButton" runat="server"
    CommandName="Edit" AlternateText="Edit" ToolTip="Edit"/>
    <asp:ImageButton ImageUrl="~/img/cross.png" ID="DeleteButton" runat="server"
    CommandName="Delete" ToolTip="Delete" AlternateText="Delete"
    Visible='<%# ToggleDelete(Eval("catID").ToString()) %>'
    OnClientClick="return confirm('Are you sure you want to delete?')" />
     
    </ItemTemplate>
    <EditItemTemplate>
     
    <asp:ImageButton ImageUrl="~/img/accept.gif" ID="SaveButton" runat="server" CausesValidation="true"
    CommandName="Update" AlternateText="Save" ToolTip="Save" ValidationGroup="EditCategory"/>
    <asp:ImageButton ImageUrl="~/img/cancel.gif" ID="CancelButton" runat="server"
    CommandName="Cancel" ToolTip="Cancel" AlternateText="Cancel" />
     
    </EditItemTemplate>
    </cc1:C1TemplateField>
    <cc1:C1TemplateField HeaderText="Category Name" SortExpression="catName">
    <ItemTemplate>
    <asp:Label ID="NameLbl" runat="server" Text='<%# Eval("catName") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="NameTB" runat="server" Text='<%# Bind("catName") %>' MaxLength="100"
    ValidationGroup="EditCategory"></asp:TextBox>
    </EditItemTemplate>
    </cc1:C1TemplateField>
    <cc1:C1TemplateField HeaderText="System Name" SortExpression="sysName">
    <ItemTemplate>
    <asp:Label ID="SysLbl" runat="server" Text='<%# Eval("sysName") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:DropDownList runat="server" ID="SysDDL" DataSourceID="SysNamesDS"
    DataTextField="sysName" DataValueField="sysName" SelectedValue='<%# Bind("sysName") %>'>
    </asp:DropDownList>
    </EditItemTemplate>
    </cc1:C1TemplateField>
    </Columns>
    <EmptyDataTemplate>
    No items found.
    </EmptyDataTemplate>
    </cc1:C1GridView>

    .cs:
            protected void gvC1Categories_RowDeleting(object sender, C1GridViewDeleteEventArgs e)
    {
    Guid key1 = (Guid)e.Keys[0];
    int i = e.RowIndex;
    vvlmgr.DeleteCat(key1);
    }

    protected void gvC1Categories_RowDeleted(object sender, C1GridViewDeletedEventArgs e)
    {
    gvC1Categories.DataBind();
    }


    JS runtime error afterline
    gvC1Categories.DataBind();


    It might not be anything related to C1GridView, but any help is appreciated.
  • Replied 10 September 2017, 11:41 am EST

    I found a fix which is replacing Eval with Bind in the ItemTemplate.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels