The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

esDataSource + GridView --> can't deleted/updated rows

Last post 06-17-2008, 12:50 PM by Mike.Griffin. 6 replies.
Sort Posts: Previous Next
  •  06-11-2008, 2:04 PM 9763

    esDataSource + GridView --> can't deleted/updated rows

    hi,

    I can't delete a row in my gridview.

     

    Code:
    1     protected void Page_Load(object sender, EventArgs e)
    2            {
    3                if (!this.Page.IsPostBack)
    4                {
    5                    CountforPager();
    6                }
    7    
    8            }
    9    
    10           protected void CountforPager()
    11           {
    12               Comments com = new Comments();
    13               CommentsQuery comq = com.Query;
    14               comq.Where(comq.Status == 2);
    15               comq.es.CountAll = true;
    16               comq.es.CountAllAlias = "Count";
    17               if (comq.Load())
    18               {
    19                   EsDataSrc.TotalRowCount = (int)com.GetColumn("Count"); //count for the paging
    20               }
    21               GridViewCom.Sort(CommentsMetadata.PropertyNames.DateAdded, SortDirection.Ascending);
    22           }
    23   
    24   
    25           protected void EsDataSrc_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
    26           {
    27               CommentsCollection comcoll = new CommentsCollection(); // create the source for the gridview
    28               comcoll.Query.Where(comcoll.Query.Status == 2);
    29               e.Collection = comcoll;
    30           }
    31   
    32   
    33   
    34           protected void EsDataSrc_esDelete(object sender, EntitySpaces.Web.esDataSourceDeleteEventArgs e)
    35           { //delete  
    36               Comments com = new Comments();
    37               if (com.LoadByPrimaryKey((int)e.PrimaryKeys[0]))
    38               {
    39                   com.MarkAsDeleted();
    40                   com.Save();
    41                   e.Entity.MarkAsDeleted();
    42                   CountforPager(); //update the data after delete
    43               }
    44   
    45           }
    46   
    47           protected void EsDataSrc_esUpdate(object sender, EntitySpaces.Web.esDataSourceUpdateEventArgs e)
    48           { //approve - update
    49               Comments com = new Comments();
    50               if (com.LoadByPrimaryKey((int)e.PrimaryKeys[0]))
    51               {
    52                   com.Status = 1;
    53                   com.Save();
    54                   CountforPager(); //update the data after approve 
    55               }
    56           }
    57           protected void GridViewCom_RowDeleting(object sender, GridViewDeleteEventArgs e)
    58           {
    59               int a = e.RowIndex;
    60               GridViewCom.DeleteRow(a); 
    61               CountforPager();
    62           }
    63   
    

     

    on the line '60' I have this exception : An unhandled exception of type 'System.StackOverflowException' occurred in System.dll

    I was thinking with esDataSource the delete is "automatic".

    Thanks for help !

     LN

    Filed under:
  •  06-11-2008, 6:06 PM 9767 in reply to 9763

    Re: esDataSource + GridView --> can't deleted/updated rows

    Your in RowDeleting() and calling DeleteRow() which ends up calling RowDeleting() again. Let me get you a sample, it's very easy, we have our team meeting now, will post it later

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-11-2008, 8:11 PM 9768 in reply to 9767

    Re: esDataSource + GridView --> can't deleted/updated rows

    Okay, this is very easy, all you need to do is implement the esCreateEntity event. You don't even have to delete the object. Look at the samples that come with ES2008, the esDataSource samples. Here's a sample implementation:

     

    Code:
    protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    {
    Employees entity = new Employees();

    if (e.PrimaryKeys != null)
    {
    entity.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
    }

    // Assign the Entity
    e.Entity = entity;
    }


    In fact, if you just add the delete/update buttons ES will do the rest, it will auto save and delete if you just implement the esCreateEntity event. You don't have to implement the Update or Delete events.

    On my GridView I have these properties and it saves and deletes without me doing anything other than implementing the above event.

     

    Code:
    <asp:CommandField ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="true" ButtonType="Button" InsertVisible="False" >
     

    Also, with the ES2008 Release Candidate released yesterday you don't even have to set the esDataSource.TotalRowCount as it should be done for you now.

     

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-12-2008, 12:16 PM 9786 in reply to 9768

    Re: esDataSource + GridView --> can't deleted/updated rows

    Hi,

     First , thanks for your reply !

    If I understand to be able to delete/update some row (data) of my gridview, I just need to implement the esCreateEntity. I  was thinking "EsDataSrc_esSelect" was enough Indifferent . So I add this in the code :

    Code:
    protected void EsDataSrc_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
            { 
                //implement esCreateEntity
                Comments com = new Comments();
    
                if (e.PrimaryKeys != null)
                    com.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
                else
                    com.AddNew();
    
                e.Entity = com;
            }

    I have remove the event "EsDataSrc_esDelete" and the "EsDataSrc_esUpdate", and nothing happend, When I run the application and put some breakpoint, it never goes in the method "esCreateEntity", it was the same for "esDelete" and "esUpdate", just goes in "esSelect".

    Did I have to call the method of es somewhere ? Did I have to implement some event of the datagrid ? it seems so easy... (not for me Sad)

    Thanks

  •  06-12-2008, 12:31 PM 9787 in reply to 9786

    Re: esDataSource + GridView --> can't deleted/updated rows

    Run our "C:\Program Files\EntitySpaces 2008\esDataSource\C#\Sample" demo, just change the connection string, it runs against SQL Server's Northwind. It will update (and you can add the delete button) and it will delete too.  Did you add the event by double clicking on that event in the ui?

     

    Code:
    <cc1:esdatasource id="EsDataSource1" runat="server" 
        onescreateentity="EsDataSource1_esCreateEntity" 
        onesselect="EsDataSource1_esSelect" 
        AutoPaging="True" 
        AutoSorting="True"/>
    I definitely works.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  06-17-2008, 11:36 AM 9853 in reply to 9787

    Re: esDataSource + GridView --> can't deleted/updated rows

    hi !

    The problem is fix, this is the reason :

    Code:
    "GridViewCom"  runat="server" DataKeyNames="Id"......>

     

    I don't put the "DataKeyNames" in the properties of the grid :-)

    Thanks for your help !

  •  06-17-2008, 12:50 PM 9856 in reply to 9853

    Re: esDataSource + GridView --> can't deleted/updated rows

    Ahh, I see. If I recall correctly the esDataSource control puts those in there for you when you choose your columns, it uses the primary key(s) to determine that.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML