I have two dropdown boxes (Department and SubDepartment) that are in a DetailsView. When I'm in edit mode and make a selection in the Department Dropdown, the selected Department is supposed to then be used as a parameter for the SubDepartment. I'm putting
my code in below for the department and subdepartment, and this is the error I receive when I make a selection in the Department dropdown. Any idea what I'm doing wrong?
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.
According to your description, I tried to reproduce your problem, and found that Bind("RequisitionDepartmentID") can only Bind the fields of DetailsView. If you are binding a field inside a DropDownList, the value in SelectValue must be more than one.
If you want to let Department parameter be used as a parameter for the SubDepartment,you can do this by setting the SelectCommand property.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Hi there. I've tried your sample, and it's close to working, but there is a problem that I'm curious if you know how to overcome. When the details view first loads, the ItemTemplates display the current Department and SubDepartment. HOWEVER, when in your
example, when you click edit, both values are "lost" when the edititemtemplate comes in to play. So, in a lengthly form, it's easy to miss/forget what the original value was for Department or Sub Department when the Edit button is clicked.
How do I "keep" the value selected in the drop down list, IF it's a valid value. Otherwise I want it to go to the first item in the list, which is the tect "--Select One--"
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Participant
1131 Points
1693 Posts
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a data...
May 31, 2019 01:11 PM|funluckykitty|LINK
I have two dropdown boxes (Department and SubDepartment) that are in a DetailsView. When I'm in edit mode and make a selection in the Department Dropdown, the selected Department is supposed to then be used as a parameter for the SubDepartment. I'm putting my code in below for the department and subdepartment, and this is the error I receive when I make a selection in the Department dropdown. Any idea what I'm doing wrong?
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.
Contributor
3370 Points
1409 Posts
Re: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a...
Jun 03, 2019 09:16 AM|samwu|LINK
Hi funluckykitty,
According to your description, I tried to reproduce your problem, and found that Bind("RequisitionDepartmentID") can only Bind the fields of DetailsView. If you are binding a field inside a DropDownList, the value in SelectValue must be more than one.
If you want to let Department parameter be used as a parameter for the SubDepartment,you can do this by setting the SelectCommand property.
The code:
The result:
My Table:
Test4:
Test6:
Best Regards,
Sam
Participant
1131 Points
1693 Posts
Re: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a...
Jun 03, 2019 06:26 PM|funluckykitty|LINK
Hi there. I've tried your sample, and it's close to working, but there is a problem that I'm curious if you know how to overcome. When the details view first loads, the ItemTemplates display the current Department and SubDepartment. HOWEVER, when in your example, when you click edit, both values are "lost" when the edititemtemplate comes in to play. So, in a lengthly form, it's easy to miss/forget what the original value was for Department or Sub Department when the Edit button is clicked.
How do I "keep" the value selected in the drop down list, IF it's a valid value. Otherwise I want it to go to the first item in the list, which is the tect "--Select One--"
Contributor
3370 Points
1409 Posts
Re: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a...
Jun 05, 2019 03:03 AM|samwu|LINK
Hi funluckykitty,
According to your description, I modified the code so that you can "keep" the value selected of DropDownList in the code behind.
In OnModeChanging event I get the value of the label and store them in Viewstate.
In OnDataBound event I get the control of DropDownList, then selecting default text by ViewState.
The code:
The result:
Best regards,
Sam