Scenarios
I am using DataGrid with a column containing DropDownList. When I update the values, the DropDownList value does not get updated.
My Research so far
I believe it needs some C# code to made the DropDownList editable. I don’t know where to put the code and how? Is there a shorter way than C# code?
Thank you very much
Edit : Supplied Code
student_table : id, name, major, favorite_teacher
teacher_table : id, name
The gridview has datasource of student. The DropDownList has datasource of teacher.
In the gridview with, I have made favorite_teacher as template field (DropDownList) and has teacher_table as datasource. In the edit mode, the DropDownList shows correct and populates teachers from the teacher table. When I select a favourite teacher for any student and click submit, the submit does not go through. I might need some C# code or otherwise. Don’t know how to fix this problem.
I implemented this from a tutorial here without writing any C# code.
You do not need C# code, although you can implement it using C# code as well.
There is a trick that you have to implement. You need to bind the values of gridview to a datasource of the other table that you want to fetch data from. But by design, since dropdown list is contained in GridView, it can only be bound to gridview fields. This is the main complication.
To overcome that, include those additional fields in the gridview. You may need to use join statement so that you can include all the fields that you need in gridview. Now you can easily bind those fields to DropDownlist. Of course you do not need to show these extra values in GridView, they are there only for DropDownList. This will solve your problem, without writing a single line of code.