Gridview, detailsview and inserting the first record

Posted on 2006-05-28
Last Modified: 2008-02-26

I've set up a very simple master/details page with a gridview (selectable rows) and a detailsview.
That works fine for updating, deleting and inserting as long as there is at least one record in the SQLtable.

The gridview has a SqlDataSource with this SelectCommand: "SELECT type_id, type FROM Types"
The detailsview has a SqlDataSource too with this SelectCommand: "SELECT type_id, type FROM Types WHERE type_id=@type_id"

That last SqlDataSource retrieves it's selectparamater (@type_id) from the datagrid's selectedvalue.

Now when there's no record in the database, no gridview appears. And thus no detailsview can be shown because @type_id isn't provided.

How can I show the detailsview (in defaultMode=Insert) so I can put the very first record of that SqlTable?

Hope I made myself clear enough

Thanks in advance
Question by:kGenius
    LVL 96

    Accepted Solution

    I believe that you need to add a blank record to the data source in order to get this to work.

    LVL 7

    Author Comment

    In the meantime I found the solution to the problem.
    It is exactly as you say. "SELECT 0 As type_id, '' AS type" works perfect.
    Thanks anyway.
    You get the points


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now