I have a combobox that I bind to a list of objects with three properties: int a, int b, and string x. When bound I set DataTextField to x and DataValueField to a. What I want to do is get the value of b in the code-behind after the collection has been bound to the list. I do not want to use ViewState. Can I possibly use reflection? Something like this?
var dataSource = ddlTest.GetDataSource();
var newDataSource = dataSource.GetType().GetProperty("_dataSource",
BindingFlags.NonPublic | BindingFlags.Instance);
I’m not sure about this, but you might be able to add
bas a custom attribute to theListItem. Try something like this and see if it works:If you’d prefer to use a regular foreach loop:
If adding custom attributes doesn’t work and you don’t want to use ViewState, you might have to store both
aandbin the value field, separated by a delimeter. This can be a pain because you’ll have to parse the items to get the values, but given your requirements that might be the best option if the custom attributes don’t work.