Last post Sep 01, 2008 08:07 PM by bryn.parrott
Sep 01, 2008 03:23 PM|bryn.parrott|LINK
I have a 'client' table that has a number of varchar(20) fields in which the data entry is to be resticted to the value contained in a drop down list.
By default the Dynamic Data wizard displays the fields in text boxes, and they can be readily edited.
I have added a class of my own ('Lookups') that goes off and runs a custom sql query to fetch appropriate values for the dropdownlist from a table based upon the table and fieldname.
This is invoked in the page_load for the 'clients' custom (edit) page.
I have added a new field template ('lookuplist_edit' ) that has a basic DropDownList control that gets instantiated for each field when I add the UIHint 'LookupList' to the custom edit page for 'clients'. This fetches an ArrayList from the 'Lookups' class
by first fetching the tablename from Column.Table.DisplayName and the column name from Column.DisplayName and the result is bound as the datasource to the DropDownList.
So far, so good. The edit page loads just fine, and each instance of the dropdownlist is correctly populated and the default SelectedValue is correctly set for the data stored for each client in the clients table.
Problem comes when I open up the clients edit form and then change one of the values in any of the dropdownlists. and click <update>
If I click on update, then the data saved back to the client table consists of the zero'th item in any of the dropdowns, and not the selected item.
I put some debug onto the 'OnSelectedIndexChanged' event and found that the SelectedIndex and SelectedValue are always the zero'th no matter which item is selected. When I set the control to
I found it reset the dropdown selected value to the zero'th item in the list (so it seems to be the same mechanism operating).
cannot for the life of me seem to find out where this reset to zero is happening, can anyone offer any clues ?
It strikes me I must be doing something stupid, because what I am trying to do cannot be all that ucommon (although the designers of Dynamic Data do not seem to have thought of this.. - otherwise they would have already allowed for it !!). After all its
a fairly common sort of prevalidation thing to do on a UI, i.e. to have available choices restricted by a dropdown list, list box or tick boxes or radio buttons or something like that.
Thanks in advance...
Sep 01, 2008 06:00 PM|sjnaughton|LINK
Hi Bryn I had some similar things happen when I wrote this article on my blog have a look
An Advanced FieldTemplate.
Hope this helps [:D]
Sep 01, 2008 08:07 PM|bryn.parrott|LINK
Well, that certainly did the trick !! [:P] [:)]
I was bashing my head on that some of yesterday and all day today so many thanks for sparing me more pain !!
Looking at what I implemented compared to what you showed in the blog, I was loading up the combo box in the page_load event instead of the OnDataBinding event and evidently changing this made it all work. And the
DropDownList1_DataBound event I also copied verbatim.
I had tried to get some things out of the standard foreign key edit control, but evidently that was inappropriate !.
You know, I searched everywhere in the documentation for what I shoiuld have been doing, would seem worthwhile if MS would look at what can be done in the docs to make this easier for people, I can't be the only one having trouble.
Anyway, many thanks for you help.
Custom Field Templates