Updating several rows in the datagrid

D

Dorte

In all the examples I can find for editing data through an
ASP.NET datagrid, the user can only edit one row at the
time and then update.

I need to allow the user to edit several rows/fields
before he clicks an update button. I know there is the
risk of someone else having edited data in the database in
the meantime because of the disconnected structure, but
this is not an issue in the application I am working with.

How can I let all values in a datagrid appear as
immediately editable (by letting values appear in a
textbox or similar) and when the user has finished
entering new values in the textboxes then make an update
command to update all edited values?
 
J

John Wadie

You'll have to use template columns for the fields that you want to allow
the user to edit, it could be something like

<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox Runat="server"
Text='<%DataBinder.Eval(Container.DataItem,"Field1")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>

When the user finishes entering the values you should loop over the
datagrid rows, extract the new values from the TextBox controls, and use
them to update the database.

Cheers,
John Wadie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top