I know this question has been answered many times before, but none of those replies are working for me.
I have a GridView with a TextBox column. Under specific circumstances, the TextBox column becomes a DropDown list. I have this part working fine.
I bind the DropDownList to a List<T> where T is an object, say CustomerType for example. Normally, I would bind the DisplayMember to the "TypeName" property and the ValueMember to the "CustomerTypeId" property and all would be well.
But because the TextBox column is bound to the "TypeName" of the object instead of the Id, I need some code to get the Id from the combobox.
I tried adding code to the ValueChanged event, but I am always getting the wrong element. Here is my code:
Any tips?
I have a GridView with a TextBox column. Under specific circumstances, the TextBox column becomes a DropDown list. I have this part working fine.
I bind the DropDownList to a List<T> where T is an object, say CustomerType for example. Normally, I would bind the DisplayMember to the "TypeName" property and the ValueMember to the "CustomerTypeId" property and all would be well.
But because the TextBox column is bound to the "TypeName" of the object instead of the Id, I need some code to get the Id from the combobox.
I tried adding code to the ValueChanged event, but I am always getting the wrong element. Here is my code:
Private Sub CustomerGridView_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CustomerGridView.ValueChanged If CustomerGridView.CurrentRow IsNot Nothing AndAlso Me.CustomerGridView.Columns(COL_customerType).IsCurrent Then Dim editor = TryCast(sender, RadDropDownListEditor) If editor IsNot Nothing Then Dim editorElement = TryCast(editor.EditorElement, RadDropDownListEditorElement) If editorElement IsNot Nothing Then Dim selectedItem = TryCast(editorElement.SelectedItem.DataBoundItem, CustomerType) If selectedItem IsNot Nothing The Dim currentCustomer = TryCast(CustomerGridView.CurrentRow.DataBoundItem, Customer) Customer.CustomerTypeId = selectedItem.CustomerTypeId End If End If End If End If End SubAny tips?