Using stored procedures with FormView

Posted on 2009-04-24
Last Modified: 2013-12-17
Greetings all

I am using a FormView to capture various pieces of data. For the updating/inserting I want tosuse stored procedures instead of setting the CommandName to Insert or Edit.

As far as I understand it, I enter the COmmandName for the appropriate buttons and then set up the method as follwos (see snippet).

Is this correct?

In advance, thanks!!

<asp:Button ID="btnInsertC" runat="Server" Text="Insert" CssClass="buttonsOnCollapseHeader"  />


        <asp:Button ID="btnEditC"   runat="Server" Text="Edit" CssClass="buttonsOnCollapseHeader" />


        <asp:Button ID="btnCancel"  runat="Server" Text="Cancel" CssClass="buttonsOnCollapseHeader" />

protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)


if (e.CommandName == "New")







  if (e.CommandName == "Edit")



Open in new window

Question by:allanmark
    LVL 2

    Expert Comment

    no this is not correct.

    You have to configure the FormVIew controls, Select, Delete, and Update functions by pointing them to the corresponding data source.

    The steps to setup such an environment would be:

    1) Drag drop a datasource, connectit to the corresponding Database hosting the stored proceudres you want (Use the server explorer)

    2) Drag drop the FormView to your page. Right click the form view for options. Configure your Select, Update and Delete methods by pointing them to the corresponding SPs in your database in the configured datasource

    Now the FormView will create select, insert and delete functions in your project, which you can further finetune to your needs.

    Please let me know if anything is unclear.

    Author Comment


    A couple of things ...

    1.  The DataSource is a DataTable, passed across to the UI, from a DataAccess Layer (eventually we
         will  convert to using Lists, but for now DataTables).
    2.  We are also coding in Source view, as opposed to using the Designer.
    3.  The procedure has several parameters (excluding the edited fields)

    Can I still follow the process of your steps?

    LVL 2

    Accepted Solution

    SUre you can

    Just because you are using a wizard, it does not rob the oppportunity to fine tune.

    The wizard cna easily hook up your FormView/Any presentation view control in ASP.NEt to a SQL server and procedure.

    However if you want it to make the datasource as a C# data object, then you would have to point the datasource to the C# assembly which has those objects. IN the C# assembly write four methods, which will perform select, insert, update and delete and point the Form View methods to those methods.

    Hope this is clear.

    I am not at my computer, so am not able to give oyu an exact walkthrough of the process. The wizards options are easy to understand once you open them.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now