Link to home
Start Free TrialLog in
Avatar of allanmark
allanmark

asked on

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

Avatar of Kalpana_Natarajan
Kalpana_Natarajan

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.
Avatar of allanmark

ASKER

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?



ASKER CERTIFIED SOLUTION
Avatar of Kalpana_Natarajan
Kalpana_Natarajan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial