Would this be the same for dropdown lists?? I used the second option and the radiobuttonlist works fine now thanks...
I have a want to put a dropdown that looks up data from another table and binds to a filed on the insert form. i am using a different datasource for the dropdown and when i bind it to the field i get:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Here is the query text for the dropdown:
SELECT DMData.DMUPI, DMData.DMFName, DMData.DMLName FROM CDFData RIGHT OUTER JOIN DMData ON CDFData.CDFDMUPI = DMData.DMUPI ORDER BY DMData.DMLName
INSERT INTO CDFData(CDFDMUPI) VALUES (@CDFDMUPI)
Hi David,
Yes, you can use the same methods for the custom drop down list.
Only for the first method where additional ListItem is added, the ListItem can not be added statically because it will be overridden by the databinding against the additional data source.
Additional ListItem with 0 value can be added in two ways:
Add additional row in the dropdown list data source that will hold 0 value. This can be done with the SQL operator UNION, for example in your case:SELECT DMData.DMUPI, DMData.DMFName, DMData.DMLName DMData
UNION SELECT 0 AS Expr1, '[NOT SET]' AS Expr2, '[NOT SET]' AS Expr3
ORDER BY DMData.DMLName
The other way is using code to handle the DropDownList DataBound event which is fired after the dropdownlist is filled with data. In the event handler you can add a new ListItem protected void customDropDownList_DataBound(object sender, EventArgs e){customDropDownList.Items.Add(new ListItem("[NOT SET]", 0));}
Ok, I spoke too soon on the radiobuttonlist.
When I use the default value (suggestion 2 above) the control works when i test it until I submit the form...what is inserted is the default value not the selected choice????
Am I missing something