The following code create a Template Field for city column in the webpage.
When we will click on the edit button, Grid View row will go into edit mode and dropdownlist will be binded in country column.
Employee's current country will be selected default.
Introduction: This question has been asked many times at the forums ( and definitely there are already bunch of different solutions provided.
Most of the examples from the web are using Data Source controls (e.g Sql Data Source, Object Data Source, etc..) to implement cascading Drop Down List in Grid View and I can’t seem to find a formal example that demonstrate how to implement it without using Data Source controls.
Note: Before you proceed, make sure that you already know the basics of using the Grid View control and how to bind it with data as I will not include the details of doing edit,update or delete scenarios for this exercise.
Scenario: As a recap, Cascading Drop Down List enables a common scenario in which the contents of one list depends on the selection of another list.
The Edit Item Template is used to display user interface while Details View control is in edit mode. We use Bind() to display data and this data can take part in Insert and Update operations.
Similarly, the Insert Item Template is used to display user interface while Details View control is in insert mode. When we use Bind() method in a Template Field, the Bind() method supports two-way data binding, which means data can be updated, inserted, and deleted automatically from the data source control.
This example demonstates how to bind a Details View control with a Drop Down List control when Details View is in Edit Mode or in Insert mode. Account Cat FROM Accounts Table, Group Table WHERE Accounts Table. Group Code" Update Command="Update Accounts Table SET Account [email protected] Name, Accountdescription [email protected], Account Address1= @Account Address1, Account [email protected] Address2, Account [email protected] Phone, Account [email protected] City, Account [email protected] Opamt, Account [email protected] Clamt, Account [email protected] Cat, Account [email protected] Pgroup Where Account [email protected] Code" Insertcommand="Insert Accounts Table (Account Code, Account Name, Accountdescription, Account Pgroup, Account Address1, Account Address2, Account Phone, Account City, Account Opamt, Account Clamt, Account Cat) values(@Account Code,@Account Name,@Accountdescription,@Account Pgroup, @Account Address1,@Account Address2,@Account Phone,@Account City, @Account Opamt,@Account Clamt,@Account Cat)" runat="server"/ Using Bind() and Eval() methods in templates We are familiar with the Eval() method when using data binding expressions.
By binding the Drop Down List control to a Sql Data Source control, we can populate the Drop Down List control with the data present in the database The below code demonstrates how to place a Drop Down List control in a Edit Item Template and Insert Item Template. The difference between the Eval() method and the Bind() method is: We use Eval() method to display data and this data is not going to take part in Insert and Update operations.
Similarly, when Details View is in Insert mode, we provide a list of groups from where the user will select a group to which the account belongs.