How to invoke Edit mode in GridView when dataSource is set programatically? (ASP.NET 2.0)

M

misiek

Hi all.

I have following problem:
1. In my web page I have a GridView control, which does not have a
DataSourceId set in designer.
2. When user presses Start button then I create programatically a
dataSet, set it as a DataSource for my GridView an add it to Session.
3. I want my users to be able to edit data displayed in GridView, so I
added Edit command column.
4. When user clicks Edit, then I get the following error: "The GridView
'GridViewPI' fired event RowEditing which wasn't handled"
5. I tried to handle that event, but when I place some code to
GridViewPI_RowEditing, then columns in GridView do not change their
appearance, so edit is not possible.

How can I solve this problem?

I cannot update changed data at the moment when user clicks Update,
because he might change his mind. So I need to cache changed data and
update data in database only when user clicks Save button. That is why
I do not set DataSourceId in designer.

Maybe there is some simpler solution to do this?

Thanks in advance.
Misiek
 
A

Andrew Lam

You have probably gotten the answer by now.
If you are manually handling the RowEditing event, remember to keep the
gridview in edit mode.
Within the handler, GridViewEditEventArgs.NewEditIndex tells you the
row that is being edited, make sure that the gridview.EditIndex is set
to the NewEditIndex of the GridViewEditEventArgs.

Personally, I'll use the gridview with an ObjectDataSource together
with a business object. The business object can then return the dataset
that you created programmatically in a method specified in the
objectdatasource's SelectMethod. Then you do not have to manually
handle the mode switches, updates and deletes.
 
J

Jo

Hi all,

In the reaction of Andrew a "gridview with an ObjectDataSource together
with a business object" was suggested to use for a gridview. So "the
business object can then return the dataset that you created
programmetically...".

I'm a starter in ASP.NET and looking for a solution on this for a few
days now. Can
someone give an example in code how to implement this? I use C#.NET.

Thank you in advance!

Regards,
Jo
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top