detailsview.. insert button for empty datasource

Discussion in 'ASP .Net' started by Not Me, Feb 2, 2006.

  1. Not Me

    Not Me Guest

    Hi,

    I've seen this prob in a few places but the explanations/solution wasn't
    up to my understanding!

    I have a detailsview, with an insert button that works fine when there
    is already data in the bound datasource, but it appears blank otherwise.

    One solution was to make all fields templatefields, with itemtemplate
    and insertitemtemplate for each field. This didn't appear to change
    anything.

    I can default the detailsview control to insertmode, but that's not
    practical as if there's data there I want to see it first.

    Another option was to put a link in the emptydatatext field, which can
    call a function to change the detailsview to insertmode.

    Are there any other options? otherwise can you explain how to make a
    button fire a function in my code... I (think I) got half way with

    href="javascript:__doPostBack('button1','')" in a link, however then I'm
    getting an error telling me the event isn't validated, as it wasn't
    called by the button I placed it on (I created an invisible button with
    associated event)...

    any tips?
    Cheers,
    Chris
     
    Not Me, Feb 2, 2006
    #1
    1. Advertising

  2. Not Me

    Not Me Guest

    Solved it! (or rather someone else did, I found bits of similar things
    elsewhere and stuck it together)...

    Not Me wrote:
    > I have a detailsview, with an insert button that works fine when there
    > is already data in the bound datasource, but it appears blank otherwise.

    <snip>
    > Another option was to put a link in the emptydatatext field, which can
    > call a function to change the detailsview to insertmode.

    <more snip>
    > href="javascript:__doPostBack('button1','')" in a link, however then I'm
    > getting an error telling me the event isn't validated, as it wasn't
    > called by the button I placed it on (I created an invisible button with
    > associated event)...


    ....with the following

    Protected Overrides Sub Render(ByVal writer As
    System.Web.UI.HtmlTextWriter)

    ClientScript.RegisterForEventValidation("button1")
    MyBase.Render(writer)

    End Sub


    Cheers,
    Chris
     
    Not Me, Feb 3, 2006
    #2
    1. Advertising

  3. Try using the DataItemCount property for the DetailsView. If it's zero,
    then you can force CurrentMode to Insert.

    I haven't tried this yet, so I'm not sure where you will need it to get it
    to work. I'd try the DataBound event first.
    --
    Christopher A. Reed
    "The oxen are slow, but the earth is patient."

    "Not Me" <> wrote in message
    news:drtd8n$f3j$...
    > Hi,
    >
    > I've seen this prob in a few places but the explanations/solution wasn't
    > up to my understanding!
    >
    > I have a detailsview, with an insert button that works fine when there is
    > already data in the bound datasource, but it appears blank otherwise.
    >
    > One solution was to make all fields templatefields, with itemtemplate and
    > insertitemtemplate for each field. This didn't appear to change anything.
    >
    > I can default the detailsview control to insertmode, but that's not
    > practical as if there's data there I want to see it first.
    >
    > Another option was to put a link in the emptydatatext field, which can
    > call a function to change the detailsview to insertmode.
    >
    > Are there any other options? otherwise can you explain how to make a
    > button fire a function in my code... I (think I) got half way with
    >
    > href="javascript:__doPostBack('button1','')" in a link, however then I'm
    > getting an error telling me the event isn't validated, as it wasn't called
    > by the button I placed it on (I created an invisible button with
    > associated event)...
    >
    > any tips?
    > Cheers,
    > Chris
    >
     
    Christopher Reed, Feb 4, 2006
    #3
  4. Not Me

    diegowarrior

    Joined:
    Oct 8, 2006
    Messages:
    1
    Hi,

    The only thing you have to do is change the Default Mode to "Insert" from "ReadOnly"!!

    :-D

    diegowarrior
    Bye!
     
    diegowarrior, Oct 8, 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. Justin Rich

    Detailsview empty dataset insert

    Justin Rich, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,275
    Justin Rich
    May 19, 2005
  2. Eric Zhao

    Detailsview empty dataset insert

    Eric Zhao, Aug 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,931
    Brock Allen
    Aug 30, 2005
  3. ButlerDJIAM
    Replies:
    0
    Views:
    578
    ButlerDJIAM
    Nov 9, 2006
  4. Eric Zhao

    Detailsview empty dataset insert

    Eric Zhao, Aug 30, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    155
    Brock Allen
    Aug 30, 2005
  5. Feege
    Replies:
    0
    Views:
    493
    Feege
    Dec 20, 2005
Loading...

Share This Page