editing data in a datagrid/datalist with llblgen pro

Posts   
 
    
andieje
User
Posts: 28
Joined: 17-May-2006
# Posted on: 17-May-2006 23:05:09   

Hi

I am considering buying llblgen and i want to make sure i understand how to do some of the things i often do in asp.net.

If i have a datalist/datagrid bound to a collection of entity objects and the datagrid is in edit mode, how do i persist the changes the user has made back to the database with llblgen?

I often do multirow editting in a datalsit whereby i simply display the data using using an item template that contains textboxes. Again, how would i persist these changes back to the database.

Please could you use the customers table in northwind as an example if you are kind enough to answer.

Also, how do you page through records using llblgen? I presume you can use the built in paging facilities of the datagrid. Is there any benefit to doing custom paging with llblgen pro whereby you only retrieve the required number of records at a time? If so, how would you do this?

Thanks a lot for your help andrea

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-May-2006 07:19:37   

how do i persist the changes the user has made back to the database with llblgen?

Again, how would i persist these changes back to the database.

You would call the coresponding save method.

In SelfServicing scenario:

collection.SaveMulti();

In Adapter scenario:

adapter.SaveEntityCollection(collection);

how do you page through records using llblgen?

Please refer to the "Using the generated code -> SelfServicing/Adapter -> Entity collection and Typed List/Typed View paging"

andieje
User
Posts: 28
Joined: 17-May-2006
# Posted on: 18-May-2006 20:40:57   

Hi

Thanks for your reply. I was actually hoping for a more detailed answer than that.

For example, lets say I want to edit the customers in the northwind database. I get a collection of Customer entities and bind the collection to a datagrid or a datalist. My datalsit is set up such that the item template contains textboxes for all the fields so that the user can edit all of the rows, a bit like an excel spreadsheet.

When the user clicks submit/edit, then what do i do?

How do i get the data from the datagrid back into the database using llblgen?

Could you give me an example in code?

This is how i imagine it will work in click event:

  • retrieve the collection of customer entities from the database
  • loop through each row in the datagrid and get the data
  • with the primary key of the row in datagrid, find the customer entity in the collection and set its fields with the values from the datagrid
  • save the collection using save all or somethng equivalent

Please culd you give me an example in code.

I am also wondering if i have to retrieve the customers collection again in the update button click event or whether it is still available to me somehow because i bound it to the datagrid. I am used to using data readers.

Thanks andrea

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-May-2006 08:18:25   

When the user clicks submit/edit, then what do i do? How do i get the data from the datagrid back into the database using llblgen? Could you give me an example in code?

Code for Adapter/C# VS 2003:


EntityCollection MyCollection = new EntityCollection(new MyEntityFactory());
foreach(DataGridItem dgItem in MyDataGrid.Items)
{
int nID = Int32.Parse(dgItem.Cells[0].Text); // you may check if you don't have a valid PK then you should skip the next 2 lines of code(i.e. doing an Insert rather than an update)

MyEntity myEntity = new MyEntity(nID); // you have to set the PK of each entity when updating existing entities
myEntity.IsNew = false; // use this line when updating existing entities            

myEntity.Field1 = dgItem.Cells[...// populating fields/properties from the datalist/datagrid cells
.
.
        
MyCollection.Add(myEntity);
}

if(MyCollection.Count > 0)
{
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.SaveEntityCollection(MyCollection);
}

As you see from the above code sample, you don't need to retrieve the collection before updating it.