mahesh  kumar

mahesh kumar

  • 2.1k
  • 20
  • 347

dynamically bind item template , edit template to gridview codebehind

Jul 1 2021 5:14 AM

I have multiple tables which need to be bind to the grdiview at run time during code behind:  one such table example is the employee mapping table which will be bind to grid view.

At the time of editing the grid view, we need to bind the dropdown to some of the columns and these columns display dropdown at the time of editing the data rows. and each dropdown will be sourced for different tables and different select and display fields. 

for the city, it has been multi-select dropdown values when the grid is in edit mode. can this be done?

  id  employee id   qualificationid cityid
100  232  161   86,87
101 233   162    85,84
 qualificationid qualificationname
 161   BE (IT)
162   Btech (CSE)
164 MBBS


city table
city id city name
86    Rajkoat
87 ahmedabad


Employee table
employeeid  emplyeename
 232  Nilesh
233  purnima

once the gridview is loaded, it should display the employee_mapping table by joining city and qualification tables to show cityname and qualificationname instead of their ids in gridview. 

once grdiview is in edit mode , dropdown should be visible:   in dropdown,  data display field should be "qualification Name" and data selected value field must be "qualification id"  from qualification table.

can we do this at run time using code behind .?

for simple bound fields, we can do simply as : 

BoundField nameColumn = new BoundField();
nameColumn.DataField = "mappingID";
nameColumn.HeaderText = "Employee ID"; 

but how to bind the template fields and item template and edit item templates along with multi select dropdowns and saving the values to database?

Answers (1)