473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with FormView and DropDownLists

I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm
using a formview to insert an order into a database. Part of the order is the
customer. Currently, I have a dropdownlist bound to a datasource that simply
selects all customers from a database table. The DropDownList's Selectedvalue
is bound with the following expression:

Bind("customerI d")

This works perfectly, the id is passed to a stored procedure and the order
is insterted. However, rather than provide a list of all customers, I'd like
to provide a dropdownlist of companies. If the user selects one of the
companies, the page posts back (the lists autopostback is set to true), and
then the dropdownlist for the customers should show only the customers
related to that company.

I added a clause to the customer datasource that ensures it only selects
customers related to the currently selected company. (It uses a control
parameter that refers to the company dropdownlist's selected value.) However,
when I run the page, and try to select a company, Visual studio gives me the
following message:

"There is no source code available for the current location." Followed by an
"OK" and a "Show Disassembly" button. When I press OK, I get an
"InvalidOperati onException was unhandled by user code" message, informing me
that "Databindin g methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

I have no idea where I'm going wrong. Does anybody have a clue?

Here's the code from the InsertItemTempl ate:

<asp:DropDownLi st ID="CompanyDrop DownList" runat="server"
AutoPostBack="T rue" DataSourceID="C ompanySqlDataSo urce"
DataTextField=" companyName" DataValueField= "companyId" >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CompanySqlD ataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSour ce>

<asp:DropDownLi st ID="CustomerDro pDownList" runat="server"
DataSourceID="C ustomerSqlDataS ource"
DataTextField=" lastName"
DataValueField= "personId" SelectedValue=' <%# Bind("customerI d") %>' >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CustomerSql DataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Comp anyDropDownList "
Name="companyId " PropertyName="S electedValue" />
</SelectParameter s>
</asp:SqlDataSour ce>


This is the InsertParameter for the FormView's datasource:

<InsertParamete rs>
<asp:Paramete r Name="customerI d" Type="Int32" />
<InsertParamete rs>

Apr 10 '06 #1
3 2010

http://www.webswapp.com/codesamples/...s/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Bas Paap" wrote:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm
using a formview to insert an order into a database. Part of the order is the
customer. Currently, I have a dropdownlist bound to a datasource that simply
selects all customers from a database table. The DropDownList's Selectedvalue
is bound with the following expression:

Bind("customerI d")

This works perfectly, the id is passed to a stored procedure and the order
is insterted. However, rather than provide a list of all customers, I'd like
to provide a dropdownlist of companies. If the user selects one of the
companies, the page posts back (the lists autopostback is set to true), and
then the dropdownlist for the customers should show only the customers
related to that company.

I added a clause to the customer datasource that ensures it only selects
customers related to the currently selected company. (It uses a control
parameter that refers to the company dropdownlist's selected value.) However,
when I run the page, and try to select a company, Visual studio gives me the
following message:

"There is no source code available for the current location." Followed by an
"OK" and a "Show Disassembly" button. When I press OK, I get an
"InvalidOperati onException was unhandled by user code" message, informing me
that "Databindin g methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

I have no idea where I'm going wrong. Does anybody have a clue?

Here's the code from the InsertItemTempl ate:

<asp:DropDownLi st ID="CompanyDrop DownList" runat="server"
AutoPostBack="T rue" DataSourceID="C ompanySqlDataSo urce"
DataTextField=" companyName" DataValueField= "companyId" >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CompanySqlD ataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSour ce>

<asp:DropDownLi st ID="CustomerDro pDownList" runat="server"
DataSourceID="C ustomerSqlDataS ource"
DataTextField=" lastName"
DataValueField= "personId" SelectedValue=' <%# Bind("customerI d") %>' >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CustomerSql DataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Comp anyDropDownList "
Name="companyId " PropertyName="S electedValue" />
</SelectParameter s>
</asp:SqlDataSour ce>


This is the InsertParameter for the FormView's datasource:

<InsertParamete rs>
<asp:Paramete r Name="customerI d" Type="Int32" />
<InsertParamete rs>

Apr 10 '06 #2
Excellent! That worked perfectly. Such a simple solution, too.

I never would've guessed that the formview wouldn't be re-bound, but
automatically recreated from the ViewState. Wouldn't it be possible to force
the formview to rebind rather than have it recreated from the ViewState? That
way you could, (I'm just guessing here), leave the dropdownlist's 2-way
databinding intact and automated.

Anyway, this works perfectly. Many thanks, you just saved my vacation!

"Phillip Williams" wrote:

http://www.webswapp.com/codesamples/...s/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Bas Paap" wrote:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm
using a formview to insert an order into a database. Part of the order is the
customer. Currently, I have a dropdownlist bound to a datasource that simply
selects all customers from a database table. The DropDownList's Selectedvalue
is bound with the following expression:

Bind("customerI d")

This works perfectly, the id is passed to a stored procedure and the order
is insterted. However, rather than provide a list of all customers, I'd like
to provide a dropdownlist of companies. If the user selects one of the
companies, the page posts back (the lists autopostback is set to true), and
then the dropdownlist for the customers should show only the customers
related to that company.

I added a clause to the customer datasource that ensures it only selects
customers related to the currently selected company. (It uses a control
parameter that refers to the company dropdownlist's selected value.) However,
when I run the page, and try to select a company, Visual studio gives me the
following message:

"There is no source code available for the current location." Followed by an
"OK" and a "Show Disassembly" button. When I press OK, I get an
"InvalidOperati onException was unhandled by user code" message, informing me
that "Databindin g methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

I have no idea where I'm going wrong. Does anybody have a clue?

Here's the code from the InsertItemTempl ate:

<asp:DropDownLi st ID="CompanyDrop DownList" runat="server"
AutoPostBack="T rue" DataSourceID="C ompanySqlDataSo urce"
DataTextField=" companyName" DataValueField= "companyId" >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CompanySqlD ataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSour ce>

<asp:DropDownLi st ID="CustomerDro pDownList" runat="server"
DataSourceID="C ustomerSqlDataS ource"
DataTextField=" lastName"
DataValueField= "personId" SelectedValue=' <%# Bind("customerI d") %>' >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CustomerSql DataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Comp anyDropDownList "
Name="companyId " PropertyName="S electedValue" />
</SelectParameter s>
</asp:SqlDataSour ce>


This is the InsertParameter for the FormView's datasource:

<InsertParamete rs>
<asp:Paramete r Name="customerI d" Type="Int32" />
<InsertParamete rs>

Apr 11 '06 #3
If you re-bind the FormView then you would reset the selection for the
customers dropdownlist that was supposed to set the next list's selection.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Bas Paap" wrote:
Excellent! That worked perfectly. Such a simple solution, too.

I never would've guessed that the formview wouldn't be re-bound, but
automatically recreated from the ViewState. Wouldn't it be possible to force
the formview to rebind rather than have it recreated from the ViewState? That
way you could, (I'm just guessing here), leave the dropdownlist's 2-way
databinding intact and automated.

Anyway, this works perfectly. Many thanks, you just saved my vacation!

"Phillip Williams" wrote:

http://www.webswapp.com/codesamples/...s/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Bas Paap" wrote:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm
using a formview to insert an order into a database. Part of the order is the
customer. Currently, I have a dropdownlist bound to a datasource that simply
selects all customers from a database table. The DropDownList's Selectedvalue
is bound with the following expression:

Bind("customerI d")

This works perfectly, the id is passed to a stored procedure and the order
is insterted. However, rather than provide a list of all customers, I'd like
to provide a dropdownlist of companies. If the user selects one of the
companies, the page posts back (the lists autopostback is set to true), and
then the dropdownlist for the customers should show only the customers
related to that company.

I added a clause to the customer datasource that ensures it only selects
customers related to the currently selected company. (It uses a control
parameter that refers to the company dropdownlist's selected value.) However,
when I run the page, and try to select a company, Visual studio gives me the
following message:

"There is no source code available for the current location." Followed by an
"OK" and a "Show Disassembly" button. When I press OK, I get an
"InvalidOperati onException was unhandled by user code" message, informing me
that "Databindin g methods such as Eval(), XPath(), and Bind() can only be
used in the context of a databound control."

I have no idea where I'm going wrong. Does anybody have a clue?

Here's the code from the InsertItemTempl ate:

<asp:DropDownLi st ID="CompanyDrop DownList" runat="server"
AutoPostBack="T rue" DataSourceID="C ompanySqlDataSo urce"
DataTextField=" companyName" DataValueField= "companyId" >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CompanySqlD ataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSour ce>

<asp:DropDownLi st ID="CustomerDro pDownList" runat="server"
DataSourceID="C ustomerSqlDataS ource"
DataTextField=" lastName"
DataValueField= "personId" SelectedValue=' <%# Bind("customerI d") %>' >
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="CustomerSql DataSource" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ordersystemC onnectionString %>"
SelectCommand=" SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Comp anyDropDownList "
Name="companyId " PropertyName="S electedValue" />
</SelectParameter s>
</asp:SqlDataSour ce>


This is the InsertParameter for the FormView's datasource:

<InsertParamete rs>
<asp:Paramete r Name="customerI d" Type="Int32" />
<InsertParamete rs>

Apr 11 '06 #4

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

Similar topics

7
4340
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to...
0
237
by: Larry R | last post by:
ASP.Net 2, Formview. I have a ObjectDataSource that is bound to a custom BusinessObject. On the formview, I have some dropdownlists and checkboxlist that are bound to a database for their values. I need to read the values and apply them to properties in the Business object. I have tried "catching" the fvEditUser_ItemUpdating(), but the...
1
10383
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in edit mode, everything works fine - the selected value in each list defaults to the value from the database record (selectedvalue=bind...). However,...
4
4899
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString; //open connection SqlConnection m_conn = new SqlConnection("Server=server; Database=database; UId=username; Pwd=password");
0
799
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hello, I have a formview control that has labels in ReadOnly mode and a mix of textboxes and dropdownlists for Edit mode. When switching from ReadOnly mode to Edit mode I need to hide/show controls based on a certain dropdown list value. If I switch to Edit mode and change the dropdown selection with my mouse the hiding/showing of certain...
5
6901
by: Mark Olbert | last post by:
It appears that FormView controls require the >>exact<< same layout of controls and control types in the various templates in order to function properly. Failure to do so results in a "failure to load ViewState" exception when a mode change occurs. Is this correct? If so, it would appear to defeat the >>entire point<< of being able to use...
1
1572
by: shapper | last post by:
Hello, I have a GridView where each row has an EDIT and a DELETE buttons. I also have a FormView with TextBoxes, DropDownLists, etc. When an EDIT button is pressed I make the MyFormView.Visible = True. My questions are:
4
8545
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that when it displays it shows values from the database and i have a link button edit on the ItemTemplate that changes the mode to edit mode and allows to...
3
4571
by: pankajsingh5k | last post by:
Dear all, I have a formview in which i have a DropDownList for selecting languages...there is also a add more button which when clicked shows 5 more dropdownlists so the user can select more langauges.... i have worked everything out....i made 5 additional rows below the languages DDList and set them to runat="server" and then i find these...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.