 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 17th, 2006, 02:46 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Displaying DetailsView for New/Empty Data Table
In the application I am writing I will be starting off with empty tables within a database. I'd like to use the DetailsView control to allow the end-user to enter the data into the tables. But I am finding that if the table is empty the DetailsView control does not display. Does anyone know how I allow the end-user to enter data into am empty table?
Thanks for any input.
|
|

November 17th, 2006, 10:34 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
On the detailsview set the defaultmode to insert.
David Rodrigues
"There is no box"
|
|

December 1st, 2006, 01:00 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You know, I've looked all online and I alwyas find the same solution. But no matter how many times I try, the problem will not resolve itself.
When I set the default mode to "insert" in the detailsview, it does not force the rows to be populated, it just provides blank textfields for the user to fill in and an insert button. If your select statement (I also should mention the select method is required) does not return a value, then it won't work. So assuming you receive an empty dataset from the server, how would you populate a new insert?
Is the solution to always return a dataset, no matter if the ID exists or not? This is the only way around it. This problem is killing me and I would relaly really appreciate someone's input on this.
|
|

December 6th, 2006, 08:46 PM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by kbghost
You know, I've looked all online and I alwyas find the same solution. But no matter how many times I try, the problem will not resolve itself.
When I set the default mode to "insert" in the detailsview, it does not force the rows to be populated, it just provides blank textfields for the user to fill in and an insert button. If your select statement (I also should mention the select method is required) does not return a value, then it won't work. So assuming you receive an empty dataset from the server, how would you populate a new insert?
Is the solution to always return a dataset, no matter if the ID exists or not? This is the only way around it. This problem is killing me and I would relaly really appreciate someone's input on this.
|
Drop the following code into your [page]. vb file.
Code:
Protected Sub FormView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.PreRender
If FormView1.DataItemCount = 0 Then
FormView1.ChangeMode(FormViewMode.Insert)
End If
End Sub
|
|

December 6th, 2006, 08:54 PM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I can't edit my previous post, so I'll just add a new one.
That is probably not the only event that would work, nor is it necessarily the best, it's just the one that I used, and it does the trick for me.
It's also handy if you would like one formview to be able to handle an insert by being called from another page. You can just set your select procedure or query to run off of a querystring parameter, then have the default value pass in something that would never be in your dataset. Then when you call the page with no querystring, it goes straight to insert.
|
|

December 7th, 2006, 03:08 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
wow, it looks like your way works. For some reason, I was using 0n_Databound and it didnt work. I'm not exactly sure why as it should do the same thing, theoretically. Anywyas, on_prerender looks like the way to go. Thanks a million!
|
|
 |