I have
I want to have a clean code-behind that uses binding to populate the list values and the selected index in the dropdown lists in both the MasterTableView and the Edit Form's FormTemplate.
I can make it work without adding the strings and integer fields to the ViewModel, but the code behind is extensive and messy. I can't figure out any clean way to do it.
I looked at the GridDropDownColumn control, but found that it's supposed only to have datatables underlying it (http://www.telerik.com/community/forums/aspnet/grid/populating-griddropdowncolumn-from-code-behind.aspx), and only found examples of it being bound to a source whose connection string etc. were declared in the .aspx (not in the code behind). I'm retrieving my values via Entity Framework and then a subsequent manipulation to acquire the values for the correct language, so that doesn't work for me.
I can't declaratively specify the options for the dropdown list in the .aspx due to the need to translate them, but if I don't declare them in the XAML, then I can't bind the selected value, because it finds that the corresponding list item doesn't exist. I also can't even bind the selected value in the case of the MasterTableView's view mode entry because of the need to translate the text to be displayed using a function that's called server side.
As-is, in ItemDataBound, for EACH dropdown field in my form, there's code to:
Seems like a lot of code to have for each field. Seems like there should be some point BEFORE databinding where I can set the list items in the dropdownlist control, so that the databinding can go through successfully. Just because I need to set the list items in code behind, why should I ALSO be forced to set the selected item there?
Is there a better way?
Thanks!
- A couple of dropdown lists in my RadGrid
- A multilingual application, such that the ViewModel provides an object for each property, but getting the display text requires a translation step to the user's language - can't just display the ViewModel property directly. I guess I COULD change this to have one property on the ViewModel that returns the string display value and another that returns the integer underlying value, but that seems messy to me - would much prefer a solution like IValueConverter to convert between the ViewModel and the displayed value based on the type of the property. Is that the "best practice"? Will that cause extra server round-trips, because the property that the client side form binds to requires server side logic to execute in order to produce its value?
- A form template for my EditForm
I want to have a clean code-behind that uses binding to populate the list values and the selected index in the dropdown lists in both the MasterTableView and the Edit Form's FormTemplate.
I can make it work without adding the strings and integer fields to the ViewModel, but the code behind is extensive and messy. I can't figure out any clean way to do it.
I looked at the GridDropDownColumn control, but found that it's supposed only to have datatables underlying it (http://www.telerik.com/community/forums/aspnet/grid/populating-griddropdowncolumn-from-code-behind.aspx), and only found examples of it being bound to a source whose connection string etc. were declared in the .aspx (not in the code behind). I'm retrieving my values via Entity Framework and then a subsequent manipulation to acquire the values for the correct language, so that doesn't work for me.
I can't declaratively specify the options for the dropdown list in the .aspx due to the need to translate them, but if I don't declare them in the XAML, then I can't bind the selected value, because it finds that the corresponding list item doesn't exist. I also can't even bind the selected value in the case of the MasterTableView's view mode entry because of the need to translate the text to be displayed using a function that's called server side.
As-is, in ItemDataBound, for EACH dropdown field in my form, there's code to:
- Populate dropdown values list manually in Edit Form (requires casting the bound item, getting the list of values with translations, and manually creating ListItems
- Setting selected item in Edit Form (reading the value from the underlying data source item and using .FindControl to get the control that I need to update)
- Setting default value for the dropdown list in the Insert form
- Set value for the field in the MasterTableView (again doing the translation)
Seems like a lot of code to have for each field. Seems like there should be some point BEFORE databinding where I can set the list items in the dropdownlist control, so that the databinding can go through successfully. Just because I need to set the list items in code behind, why should I ALSO be forced to set the selected item there?
Is there a better way?
Thanks!