Forms Data Controls :: Cascading DropDownList In DetailsView Field?
Feb 9, 2011
I have an ASP.NET/C# web project that uses an Entity Data Model and Entity Framework to interact with my database. I also have a DetailsView control that will serve as the control used to insert a new record. The user will need to be able to select from multiple,
cascading dropdownlist controls to determine what parent record this new record will belong to. Here is an example.Say we have an online ordering system with the following hierarchy.
Customers -> Orders -> OrderParts -> Parts
We're going to add a new part to an order, under a customer. Ultimately the orderparts table won't have a reference to a customer, just an order. The order will have the reference to the customer. In the DetailsView for the new orderparts record we will need two cascading dropdownlist controls. One for customer and one for order, since we won't want to view some crazy amount of orders all in one dropdownlist.
However, the customer dropdownlist should not be bound to the detailsview control since there is no field for it. I also don't want to use the AJAX control since I don't want to create a separate web service to provide all of this information to the dropdownlist controls.
I have created two dropdown lists. The 2nd DDL depends for values on the 1st DDL. I have written code on the SelectedIndexChanged event of 1st DDL to change values of 2nd DDL. also i have used detailsview. In the template field i have used 2 DDL mentioned above. they are having SelectedValue='<%# Bind("") %>' property. Everything works fine but when i tried to edit record in detailsview & select value from 1st DDL then it gives me following error.
Server Error in '/' Application. 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.
I have a template field in a Details View which is a dropdown selection of values.While I can get the value of the textfields in the DetailsView by using: DetailsView1.Rows(i).Cells(1).Text.ToStringI don't know how do extract a value from a dropdownlist2 contained in the DetailsView.
I've been struggling with trying to figure out how to do this for about 2 weeks now. I have a DetailsView with several template fields in it. The first field (Unit_Code) is a dropdownlist item where the user would select a Unit based off the Unit_Code's Unit Name. Further down I have a field named (System), system needs to get it's value from the selectedvalue or selectedindex that the user selected in the (Unit_Code) dropdownlist. I have another dropdownlist item (Component) that will need to get the selected value from System to sort on, so once I have the first Unit_Code to System figured out I should be able to figure out the System to Component part seeing as it will basically be doing the same thing.
Have spent hours trying to create a Dynamic Data Field Template holding a DropDownList which is extended by the AJAX Cascading DropDown extension.Final form holds multiple cascading dropdown boxes. User selects Country (Land) then Postcodes, Counties (Provincie) are populated. Once postcode is selected then towns (Plaats) are populated. The problem I am now facing is that the viewstate for the dropdown lists is not being saved/restored after an insert action or custom validation error. So basically the dropdown lists are being reset to their default values.Some code (if missing parts, just ask and I will post them) - Don't mind the code structures etc... needs some refactoring :)Attribute I created:
KlantMetaData (=> Klant is Dutch for Customer ):
DynamicDropDownList Control I created: [Code]....
Dynamic FieldTemplate created for inserts: [Code]....
I have a DetailsView control with several fields that is in insert mode. Three of them are the source of my problems and headaches.
I have three DropDownLists in template fields.
The first one is OK, bound to it's designated field in table1 in the database. The next two however have to change their bound tables according to the SelectedValue.
So far, I've managed to get it working, BUT when I insert the data I've entered, these two DropDownLists are not entered into the database.
DropDownList3 - the list that controls the other two DDLs
DropDownList4 and DropDownList5 - the list that need to change their items accordingly
DropDownList3 has six different values, so I have 6 tables for each of the other two DDLs
However I have only tried with one to see if it would work, that's why the Sub seems incomplete.
Here is the relevant part of the code:
And the DropDownList3_SelectedIndexChanged sub:
If I leave SelectedValue='<%# Bind("shelves") %>' and SelectedValue='<%# Bind("type") %>' in the <asp:DropDownList> tag of the two DDLs that change values, I get an error when the first one does the postback.
The error is:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. This error, I spent a whole day looking through forums and knowledge bases, but I could find nothing that solves my problem. Maybe the problem is me, but my boss wants this done, despite it is not my area of expertise to write code.
I am having two dropdownlist in my project,one dropdownlist for empid, another dropdownlist for month, if the user select the empid, the values are retrieved in the textbox.
In the second dropdownlist, if the user select the month in the dropdownlist it will display the leave details, its all working fine, if the user again select the first dropdownlist that means empid, I want to show the second dropdownlist as select month, how can do this.....
I have a DetailsView on the page and I have made one of the fields a TemplateField. In the EditItemTemplate and InsertItemTemplate I have a DropdownList that is databound to a table in my Sql Server database. I wanted to add an initial value to the DropdownList namely "- select -" .
I set the AppendDataBoundItems property to true and added the initial value as a ListItem.Markup of the DropdownList
This works fine for new input. The problem is however that the database already has records that were entered through a Windows Application and many of these records has a null value in this field and exceptions are thrown when I tried to open these records and the system tried to set the SelectedValue of the DropdownList.After some more searching I found this help
This now solved the problem of opening a record where the value is null in the database, BUT now the RequiredFieldValidator is not validating anymore to make sure that a databound item is selected for this field and not the initial value "- select -". So basically now it is not checking anymore to see if valid input has been entered for the DropDownList and it accepts "- select -" thus it acts as if the field is not a required field anymore.
In short what is required is that I want to make sure that the user enters a valid selection in the DropDownList, but it must also cater for old records that do not have this field entered yet so that those old records can be opened in the DetailsView .Opening Old records (with null in that field):When these old records are opened in the DetailsView the DropDownlist should show "- select -" when the value in the database is null.
Saving records (old or new records):When saving the record in Insert mode or Update mode the RequiredFieldValidator should show that a valid input is not selected if the DropDownList is still on "- select -".
im making a details page but i want to add another filed on the detailsview i want the url of the page to have 2 parameters, one for the datasource of the detailsview and one for the field i want to add how can i accomplish that? for example:
and then the detailsview will have the details of account 12, and one more field that has value 50,00
I have a Details view where I want to have a multi-select value, with the choices driven from another table.I need to iterate through the check-boxes in the list, and I do that by using a DetailsView1.FindControl("MyCheckBoxList") to find the check box list.The challenge I'm having now is that if I name the CheckBoxList differently in each of the templates (Item, Edit, Insert), then they each need a separate handler to find the control and iterate through the checkboxes. I can't find a method to fire a handler
I have a field that is based on asp.net membersip UserID. I can bind this to dropdowns which aren't in a detailsview just fine, but for somereason my code isnt working for finding the control properly.I have the following in detailsview.databound (where it was suggested to be placed)
A TemplateField of a DetailsView can be assigned a value easily at any of many event handlers such as Load, PreRender, etc. when the page is loaded. However, after Insert or Cancel is clicked, all the fields are cleared. I cannot figure out how to assign a value to the field again in code-behind.
I have a SQL DB with just 2 fields, ID and TEXT.What i was trying to do, was placing a Detailsview in EDIT MODE, then selecting from the DB like SELEC TOP 1 Text FROM DB.Then i placed a Ajax HTML Editor in the template field.How can i, keep the HTML Editor on the page, and use it for INSERT and/OR EDITING ?e.g.: on the first time the user opens the site management page, it will be blank, so it will show the HTML with no text on it. but the bottom button will be UPDATE and CANCEL. So when he enters the TEXT he clicks on UPDATE.
I have 5 dropdown list (sector-country-year-project code-project title) so what i need is when i select specific sector for example education , the rest of the label should show me the only data related to the sector education in dropdown list. the same with other if i select year 2011 should show me in other dropdown list just the data related to year 2011.
How do i use drop down list in the details view? While inserting user should be able to select the "Car Name" from the drop downlist and the "Car Id" should be get inerted into database. Also while editing the appropriate Car Name should be selected in the drop down list.
How the HTML code and the Binding should look for this details view ?
I'm trying to add an DropDownList to a DetailsView by code, because i'm writing a solution that let's the user select an table and view your records and edit them, some of theese tables, have a foreign key column and the user must have to select some item in the list.
Below is my sample code:
the code above is working correctly, when the user click in the buttons New or Edit , the DetailsView opens correctly, showing the DropDownlist, but when the user click in the buttons update or insert , an error occurs, the viewState cannot be loaded:
Failed to load viewstate. The control tree which viewstate is being loaded must match the control tree used to save viewstate during the previous request. For example, when controls are added dynamically, the controls added during a post must match the type and position of the controls added during the initial request.