Updating a datagrid

Posts   
 
    
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 04-Nov-2004 16:12:30   

Hi,

i have an entityCollection that a bind to a datagrid (autogeneratecolumns=true)

i can edit the rows, but whta do i have to when i get the update-event (thus i click on the update-link)

i see no changes and FooEntityCollection.savemulti(true) doesn't work either....

Public Sub DataGrid_Update(ByVal Source As Object, _ ByVal E As DataGridCommandEventArgs) 'should i use this??? 'Dim txtName As TextBox = E.Item.Cells(2).Controls(0) 'Dim txtAddress As TextBox = E.Item.Cells(3).Controls(0) 'Dim txtID As String = E.Item.Cells(1).Text

  FooDataCollection.SaveMulti(True)

  DataGrid.EditItemIndex = -1
  BindData("")

End Sub

mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 04-Nov-2004 16:41:40   

hmm, i found it:

FooDataCollection(DataGrid.EditItemIndex).foo1 = foo1String

but is it also possible to say something like this:

FooDataCollection(DataGrid.EditItemIndex).fields(1) = foo1String

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Nov-2004 16:49:48   

I'm not sure what the Update link is? Is this asp.net related or winforms related? Because when you bind a collection to a datagrid in winforms, you don't have to do anything: the values are stored inside the entity fields automatically, you just have to call SaveMulti(true) when you want to save the changes.

Frans Bouma | Lead developer LLBLGen Pro
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 08-Nov-2004 08:15:28   

it's asp.net.

when i only use savemulti(true) i don't see any changes in my datagrid.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 08-Nov-2004 10:49:43   

mafti wrote:

it's asp.net.

when i only use savemulti(true) i don't see any changes in my datagrid.

2-way databinding doesn't exist (yet) in ASP.NET (comes with .net 2.0 next year if I recall correctly). Today's ASP.NET can only do 1-way databinding. This means that if you bind a collection to a webgrid, it will use that collection to generate the grid, and then send it to the client. However, once that's done, the collection you bound to the grid is destroyed. So you can edit values on teh webpage, but that's totally client-side javascript/html. When you click a link, you get a postback, which sends the values back to the server. It is thus important you keep the objects around for the postback, for example in the session object.

When the postback comes, you have to check which rows were updated in the grid, update the fields of the bound entities (which you retrieve from the session) with these new values and THEN save these objects.

Frans Bouma | Lead developer LLBLGen Pro