Click here to Skip to main content
15,032,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>Master details dropdown error with data binding after filtration (Category / Subcategory)
I need help with fixing the problem. Both dropdowns lists are part of FormView and part of the "InsertItemTemplet". The first one selects Category (I checked the autopostback) the second dropdown Subcategory filters only records that are matching per categoryID. The dropdown Subcategory is taking data from table (Subcategory_ID, Subcategory, Category_ID)
They are connected via Control Category Dropdown List "Where Categry_ID = Category_ID".

But if I select Binding for Selected Value Bind("Subcategory_ID") then I get error (without binding the filtration works perfect).

I need to be able to select category and subcategory and both selections to enter the database.
I am using Visual studio 2012 vb.net and dropdowns directly accessing SQLDataSource

I would appreciate If anyone has any solution or suggestion on how to make it work
Thanks

Here is the error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

Line 101: <br />
Line 102: Subcategory_ID:
Line 103: <asp:DropDownList ID="DropDownListSubcategory" runat="server" DataSourceID="SqlDataSource_Subcategory" DataTextField="SubCategory" DataValueField="Subcategory_ID" Height="46px" Width="212px" AutoPostBack="True" SelectedValue='<%# Bind("Subcategory_ID") %>'>
Line 104: </asp:DropDownList>
Line 105: <asp:SqlDataSource ID="SqlDataSource_Subcategory" runat="server" ConnectionString="<%$ ConnectionStrings:GARNETConnectionString %>" SelectCommand="SELECT * FROM [SubCategory_TB] WHERE ([Category_ID] = @Category_ID) ORDER BY [SubCategory]">
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900