detailsview.. insert button for empty datasource

N

Not Me

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
 
N

Not Me

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

Not said:
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.
Another option was to put a link in the emptydatatext field, which can
call a function to change the detailsview to insertmode.
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
 
C

Christopher Reed

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.
 
Joined
Oct 8, 2006
Messages
1
Reaction score
0
Hi,

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

:-D

diegowarrior
Bye!
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top