473,238 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

How to reference a control inside a formview template from a sqldatasource?

I'm trying to create a formview bound to a sqldatasource, and use a
stored procedure to insert data from the formview into several tables.
I have some simplified code below, the real code is much longer but
this should illustrate the problem:

<asp:FormView ID="bookFormView" runat="server"
DataSourceID="bookSqlDataSource">
<ItemTemplate>
<asp:textBox id="name"
text='<%# Eval("name") %>'
runat="server" />
<asp:textbox id="city"
text='<%#Eval("city") %>'
</ItemTemplate>
<InsertItemTemplate>
<asp:textBox id="name"
text='<%# Bind("name") %>'
runat="server" />
<asp:textbox id="city"
text='<%#Bind("city") %>'
runat = "server" />
</InsertItemTemplate>
</asp:FormView>

<asp:SqlDataSource ID="bookSqlDataSource" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.Provide rName %>"
InsertCommandType="StoredProcedure"
InsertCommand="usp_add_person"
SelectCommand="select name, city from view_namecity" >
<InsertParameters>
<asp:ControlParameter Name="Name" ControlID="???"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="TRUE"
Size="20" />
<asp:ControlParameter Name="City" ControlID="???"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="TRUE"
Size="20" />
</InsertParameters>
</asp:SqlDataSource>

The problem I'm having is in what to specify in the ControlID attribute
of the SQLdatasource's insertParameter. It seems that the only object
it will recognize is the Formview (ie. ControlID="bookFormView"). But
that isn't specifically the control that the param should be bound to.
But it doesn't understand if I specify ControlID="name" -- I think
that's because the page doesn't have such a control, the control is
embedded in the insertTemplate of the FormView. I've even tried
something like ControlID="bookFormview.FindControl('name')" but that
doesn't work either. How can I get a handle for the control that's
embedded inside the formview's template?

Or am I approaching this the wrong way? Should I specify the parameter
list inside the insertCommand: insertCommand="usp_add_person @name,
@city"? I can't really do that either because a couple of the
parameters are coming in from session and application variables, not
from the formview at all. I have to use a stored procedure because I
need to insert into multiple tables, and the app design won't allow me
to use triggers either.

Thanks, I hope someone can understand this question and has some
experience with this!

-- Ned

Jul 7 '06 #1
2 9843
Ned,

You simply need to use the Bind() method when binding any of your
fields to the FormView and then when you Insert or Update it will
automatically read the new values into your parameters. Use the
regular <asp:Parameter /to fill the values from the FormView, and
<asp:SessionParameter /to fill from session variables.

To make things easy on yourself, make sure all of your parameter names
match from your stored proc, to your parameter variables in your
SqlDataSource, to your FormView.

This should allow everything to just work. It is really pretty nice,
once you get used to it.

One more thing you might run into if you use Guids in your database.
There is currently a bug when it comes to passing Guids throught he
<asp:Parameter /variable. The wizard will default the type="object"
but you will want to just delete that and leave the type out and
everything will work.

Also, you should be able to use the FormView wizard to configure all of
this.

HTH,
Chris

Jul 8 '06 #2
Chris,

Sorry for the late reply and thanks for your help -- this did work. I
was making it more complicated than it was. I assumed a control inside
a formview was a control, so was trying to use a controlParameter
instead of just a Parameter. At the moment I am not using GUIDs but I
may modify the code to use them.

Thanks again.

-- Ned
chris wrote:
Ned,

You simply need to use the Bind() method when binding any of your
fields to the FormView and then when you Insert or Update it will
automatically read the new values into your parameters. Use the
regular <asp:Parameter /to fill the values from the FormView, and
<asp:SessionParameter /to fill from session variables.

To make things easy on yourself, make sure all of your parameter names
match from your stored proc, to your parameter variables in your
SqlDataSource, to your FormView.

This should allow everything to just work. It is really pretty nice,
once you get used to it.

One more thing you might run into if you use Guids in your database.
There is currently a bug when it comes to passing Guids throught he
<asp:Parameter /variable. The wizard will default the type="object"
but you will want to just delete that and leave the type out and
everything will work.

Also, you should be able to use the FormView wizard to configure all of
this.

HTH,
Chris
Jul 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pete | last post by:
I seem unable to get the FormView with the SqlDataSource control in ASP.NET 2.0 beta 2 to insert into my MySQL 4.11 database corectly. When I run the page and click on the Insert link a SQL insert...
3
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
0
by: nate | last post by:
the error returned is this: Server Error in '/AnnAccRpt' Application. -------------------------------------------------------------------------------- Could not find control 'DropDownList1' in...
3
by: Marcial | last post by:
Greetings all! After a week of toiling I've finallay decided to post the code below with hopes that someone can point out my error(s). Basically I have a Gridview/Formview on a ASP.NEt 2.0...
0
by: davidgreen24 | last post by:
Suppose I have a SQLDataSource object that returns 20 rows. I have a FormView object bound to this control. Now when I click a hyperlink (with querystring param called productID) I want the row...
3
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
0
by: Cirene | last post by:
I have a formview that is calling a stored procedure (thru an sqldatasource) to update 2 tables. When I execute the update it runs fine, with no errors. But the data does NOT change. Any ideas...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.