Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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
 
Old November 17th, 2006, 02:46 AM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

 
Old November 17th, 2006, 10:34 AM
Authorized User
 
Join Date: Nov 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to davidrodrigues40
Default

On the detailsview set the defaultmode to insert.

David Rodrigues
"There is no box"
 
Old December 1st, 2006, 01:00 PM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old December 6th, 2006, 08:46 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old December 6th, 2006, 08:54 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



 
Old December 7th, 2006, 03:08 PM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble displaying DetailsView & FormView Sheri B ASP.NET 2.0 Basics 0 November 11th, 2006 04:08 PM
Displaying data in a table Mike707 Dreamweaver (all versions) 1 April 19th, 2006 01:43 PM
Displaying Excel data in a table badgolfer ASP.NET 1.0 and 1.1 Basics 6 January 6th, 2006 04:25 AM
Displaying Access table data into Msflexgrid using Kaustav Pro VB Databases 0 September 25th, 2005 01:08 PM
Help displaying data in table Calibus Classic ASP Databases 3 July 2nd, 2004 08:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.