On a current project I ran into a need to have a SharePoint list where the values for the selection fields (dropdowns, radio buttons etc.) were not known until run-time. Although SharePoint does support a very simple lookup function it doesn't natively support the ability to call C# code to get dynamic values for the selection lists.
I wanted to do this in the least intrusive way possible within my custom list template so I decided that adding a web control to the bottom of the EditForm.aspx and Upload.aspx that would emit the appropriate JavaScript would suffice for the requirement. Since SharePoint builds list forms using client side JavaScript (take a look at OWS.JS for all the functions) this model isn't too far from the native architecture.
The hardest part of the solution was coming up with the correct JavaScript that could replace existing form fields with my new field that had the dynamically retrieved values. After some trial and error I came up with the following code that uses DHTML to replace an existing field with a newly created field using the OWS.JS object model:
<script language="javascript" type="text/javascript">
var fieldname = "MYFIELDNAME";
fld = new ChoiceField(frm,fieldname,frm.FindField(fieldname).stDisplay,"DEFAULT VALUE");
fld.fRequired = frm.FindField(fieldname).fRequired;
fld.format = "Dropdown";
fld.AddChoice("Drop", "");
fld.AddChoice("Down", "");
fld.AddChoice("Test", "");
document.forms[frm.stName].elements[frm.stFieldPrefix + fieldname].parentNode.innerHTML = fld.stBuildUI();
</script>
<script language="javascript" type="text/javascript">
var fieldname = "MYFIELDNAME";
fld = new ChoiceField(frm,fieldname,frm.FindField(fieldname).stDisplay,";#Jonathan;#Portal;#");
fld.fRequired = frm.FindField(fieldname).fRequired;
fld.format = "Checkboxes";
fld.AddChoice("Jonathan", "");
fld.AddChoice("Loves", "");
fld.AddChoice("SharePoint", "");
fld.AddChoice("Portal", "");
fld.AddChoice("Server", "");
document.forms[frm.stName].elements[frm.stFieldPrefix + fieldname].parentNode.innerHTML = fld.stBuildUI();
</script>