GridView/FormView (master/details) questions

Discussion in 'ASP .Net' started by dan, Mar 26, 2008.

  1. dan

    dan Guest

    Hi,

    I have a hard time finding an example with GridView and FormView on the same
    page. So I'm hoping that someone will be able to help me with the following:

    1) How do I refresh GridView after Insert, Update, and Delete in a linked
    FormView?
    That is, I'd like the GridView to show updates made to a row, show a newly
    added row, and remove a deleted row.

    2) How do I force the FormView to display in InsertMode if no items are
    present in the associated GridView?
    I know that I need to call ChangeMode() on the FormView but I'm not sure
    where. I tried Selected event of the associated ObjectDataSource with "if
    (e.RowsAffected < 1) FormView.ChangeMode(FormViewMode.Insert)" but this
    does not seem to work. The ObjectDataSourceStatusEventArgs.RowsAffected is
    always -1 regardless of how many rows are displayed in the GridView. So I
    must be checking it in the wrong place.

    Any help will be greatly appreciated.
    Thanks,
     
    dan, Mar 26, 2008
    #1
    1. Advertising

  2. dan

    Stan Guest

    On 26 Mar, 22:19, "dan" <> wrote:
    > Hi,
    >
    > I have a hard time finding an example with GridView and FormView on the same
    > page. So I'm hoping that someone will be able to help me with the following:
    >
    > 1) How do I refresh GridView after Insert, Update, and Delete in a linked
    > FormView?
    > That is, I'd like the GridView to show updates made to a row, show a newly
    > added row, and remove a deleted row.
    >
    > 2) How do I force the FormView to display in InsertMode if no items are
    > present in the associated GridView?
    > I know that I need to call ChangeMode() on the FormView but I'm not sure
    > where.  I tried Selected event of the associated ObjectDataSource with "if
    > (e.RowsAffected <  1) FormView.ChangeMode(FormViewMode.Insert)" but this
    > does not seem to work.  The ObjectDataSourceStatusEventArgs.RowsAffected is
    > always -1 regardless of how many rows are displayed in the GridView. So I
    > must be checking it in the wrong place.
    >
    > Any help will be greatly appreciated.
    > Thanks,


    1) Execute the GridView's DataBind() method in the event handlers for
    the FormView's ItemInserted, ItemUpdated and ItemDeleted events.

    2) In the Page_load event handler execute the FormView's ChangeMode()
    method if the GridView's Rows.Count property is zero.

    HTH
     
    Stan, Mar 29, 2008
    #2
    1. Advertising

  3. dan

    Stan Guest

    On 29 Mar, 00:50, Stan <> wrote:
    > On 26 Mar, 22:19, "dan" <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > I have a hard time finding an example with GridView and FormView on the same
    > > page. So I'm hoping that someone will be able to help me with the following:

    >
    > > 1) How do I refresh GridView after Insert, Update, and Delete in a linked
    > > FormView?
    > > That is, I'd like the GridView to show updates made to a row, show a newly
    > > added row, and remove a deleted row.

    >
    > > 2) How do I force the FormView to display in InsertMode if no items are
    > > present in the associated GridView?
    > > I know that I need to call ChangeMode() on the FormView but I'm not sure
    > > where.  I tried Selected event of the associated ObjectDataSource with "if
    > > (e.RowsAffected <  1) FormView.ChangeMode(FormViewMode.Insert)" but this
    > > does not seem to work.  The ObjectDataSourceStatusEventArgs.RowsAffected is
    > > always -1 regardless of how many rows are displayed in the GridView. So I
    > > must be checking it in the wrong place.

    >
    > > Any help will be greatly appreciated.
    > > Thanks,

    >
    > 1) Execute the GridView's DataBind() method in the event handlers for
    > the FormView's ItemInserted, ItemUpdated and ItemDeleted events.
    >
    > 2) In the Page_load event handler execute the FormView's ChangeMode()
    > method if the GridView's Rows.Count property is zero.
    >
    > HTH- Hide quoted text -
    >
    > - Show quoted text -


    Correction:

    It might be safer to use the GridView DataBound event rather than the
    Page_Load event in (2).
     
    Stan, Mar 29, 2008
    #3
    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.

Share This Page