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

Discussion in 'ASP .Net' started by misiek, Feb 27, 2006.

  1. misiek

    misiek Guest

    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
    misiek, Feb 27, 2006
    #1
    1. Advertising

  2. misiek

    Andrew Lam Guest

    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.

    misiek wrote:
    > 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
    Andrew Lam, Mar 7, 2006
    #2
    1. Advertising

  3. misiek

    Jo Guest

    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
    Jo, Mar 22, 2006
    #3
  4. misiek

    misiek Guest

    misiek, Mar 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2VyaGFyZA==?=

    gridview row programatically set to edit mode

    =?Utf-8?B?R2VyaGFyZA==?=, Sep 29, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    14,842
    =?Utf-8?B?R2VyaGFyZA==?=
    Sep 29, 2006
  2. dba56
    Replies:
    0
    Views:
    658
    dba56
    Jan 16, 2008
  3. Replies:
    4
    Views:
    4,406
  4. RBeach1955
    Replies:
    1
    Views:
    1,853
    RBeach1955
    Jan 14, 2011
  5. Jaime Stuardo

    GridView control enters edit mode when I click Edit link twice

    Jaime Stuardo, Apr 7, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    391
    Jaime Stuardo
    Apr 7, 2006
Loading...

Share This Page