How to insert a new record in detailsview when there are no record

Discussion in 'ASP .Net Web Controls' started by Frits van Soldt, Nov 16, 2005.

  1. In the detailsview you can add a 'new' button to add new records. This works
    fine if there are already some records in the table. But when the table is
    empty, the button is not shown, thus not allowing to create any records! How
    can I show the button even if there are no records?
    Frits van Soldt, Nov 16, 2005
    #1
    1. Advertising

  2. Hi Frits,

    The SqlDataSource raises an event named "Selected". It is triggered after
    the SqlDataSource object executed the Select command. You can check the
    AffectedRows in handling this event and if it is zero then set the
    DetailsView mode to Insert.

    1- In the Page_init or Page_Load wire up an event handler for the Selected
    event of the SqlDataSource:

    SqlDataSource1.Selected += new
    SqlDataSourceStatusEventHandler(SqlDataSource1_Selected);

    2- Write an eventhandler like this:

    Void SsqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
    if(e.AffectedRows==0)
    {
    DetailsView1.ChangeMode(DetailsViewMode.Insert);
    }
    }

    --
    [note: if this post answers your question, you can mark it as an answer
    using the web-based newsreader functions]
    -----
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Frits van Soldt" wrote:

    > In the detailsview you can add a 'new' button to add new records. This works
    > fine if there are already some records in the table. But when the table is
    > empty, the button is not shown, thus not allowing to create any records! How
    > can I show the button even if there are no records?
    Phillip Williams, Nov 16, 2005
    #2
    1. Advertising

  3. RE: How to insert a new record in detailsview when there are no re

    Philip,
    thank you very much for your answer!
    I found out a different solution, I added a link called 'create new record'
    in the missing data template and in the onclick event change the detailsview
    state. But your solution is also perfect!
    Thanks again.

    "Phillip Williams" wrote:

    > Hi Frits,
    >
    > The SqlDataSource raises an event named "Selected". It is triggered after
    > the SqlDataSource object executed the Select command. You can check the
    > AffectedRows in handling this event and if it is zero then set the
    > DetailsView mode to Insert.
    >
    > 1- In the Page_init or Page_Load wire up an event handler for the Selected
    > event of the SqlDataSource:
    >
    > SqlDataSource1.Selected += new
    > SqlDataSourceStatusEventHandler(SqlDataSource1_Selected);
    >
    > 2- Write an eventhandler like this:
    >
    > Void SsqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    > {
    > if(e.AffectedRows==0)
    > {
    > DetailsView1.ChangeMode(DetailsViewMode.Insert);
    > }
    > }
    >
    > --
    > [note: if this post answers your question, you can mark it as an answer
    > using the web-based newsreader functions]
    > -----
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Frits van Soldt" wrote:
    >
    > > In the detailsview you can add a 'new' button to add new records. This works
    > > fine if there are already some records in the table. But when the table is
    > > empty, the button is not shown, thus not allowing to create any records! How
    > > can I show the button even if there are no records?
    Frits van Soldt, Nov 17, 2005
    #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.
Similar Threads
  1. =?Utf-8?B?SmF5RA==?=

    insert new record in detailsview - how to get master id

    =?Utf-8?B?SmF5RA==?=, Jul 3, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    5,724
    Richard Carpenter
    Jul 10, 2006
  2. cannontrodder
    Replies:
    1
    Views:
    705
    cannontrodder
    Jul 25, 2006
  3. MU
    Replies:
    1
    Views:
    1,190
    Paul Shapiro
    Jan 26, 2009
  4. Hanno

    Make new record current in DetailsView after Insert

    Hanno, Aug 5, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    184
    Hanno
    Aug 5, 2006
  5. Feege
    Replies:
    0
    Views:
    428
    Feege
    Dec 20, 2005
Loading...

Share This Page