G
Guest
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("customerId")
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
"InvalidOperationException was unhandled by user code" message, informing me
that "Databinding 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 InsertItemTemplate:
<asp
ropDownList ID="CompanyDropDownList" runat="server"
AutoPostBack="True" DataSourceID="CompanySqlDataSource"
DataTextField="companyName" DataValueField="companyId">
</asp
ropDownList>
<asp:SqlDataSource ID="CompanySqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings
rdersystemConnectionString %>"
SelectCommand="SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSource>
<asp
ropDownList ID="CustomerDropDownList" runat="server"
DataSourceID="CustomerSqlDataSource"
DataTextField="lastName"
DataValueField="personId" SelectedValue='<%# Bind("customerId") %>' >
</asp
ropDownList>
<asp:SqlDataSource ID="CustomerSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings
rdersystemConnectionString %>"
SelectCommand="SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParameters>
<asp:ControlParameter ControlID="CompanyDropDownList"
Name="companyId" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
This is the InsertParameter for the FormView's datasource:
<InsertParameters>
<asp
arameter Name="customerId" Type="Int32" />
<InsertParameters>
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("customerId")
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
"InvalidOperationException was unhandled by user code" message, informing me
that "Databinding 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 InsertItemTemplate:
<asp

AutoPostBack="True" DataSourceID="CompanySqlDataSource"
DataTextField="companyName" DataValueField="companyId">
</asp

<asp:SqlDataSource ID="CompanySqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings

SelectCommand="SELECT [companyId], [companyName] FROM
[company]">
</asp:SqlDataSource>
<asp

DataSourceID="CustomerSqlDataSource"
DataTextField="lastName"
DataValueField="personId" SelectedValue='<%# Bind("customerId") %>' >
</asp

<asp:SqlDataSource ID="CustomerSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings

SelectCommand="SELECT [lastName],
[personId], [companyId] FROM [person] WHERE ([companyId] = @companyId)">
<SelectParameters>
<asp:ControlParameter ControlID="CompanyDropDownList"
Name="companyId" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
This is the InsertParameter for the FormView's datasource:
<InsertParameters>
<asp

<InsertParameters>