Using stored procedures with FormView

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!!

   allanamark
<asp:Button ID="btnInsertC" runat="Server" Text="Insert" CssClass="buttonsOnCollapseHeader"  />
        &nbsp;&nbsp;
        <asp:Button ID="btnEditC"   runat="Server" Text="Edit" CssClass="buttonsOnCollapseHeader" />
        &nbsp;&nbsp;
        <asp:Button ID="btnCancel"  runat="Server" Text="Cancel" CssClass="buttonsOnCollapseHeader" />
 
 
protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "New")
{
   ..........
   ..........
   FormView1.ChangeMode(FormViewMode.ReadOnly);
}
else
  if (e.CommandName == "Edit")
   ..................
   ......................

Open in new window

allanmarkAsked:
Who is Participating?
 
Kalpana_NatarajanCommented:
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.

Regards,
Kalpana
0
 
Kalpana_NatarajanCommented:
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.
0
 
allanmarkAuthor Commented:
Thanks!

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?



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.