Hello!
I use DetailsView with ObjectDataSource to insert entry in database. DropDownList ddl_kinds is bound to some field. I complete dropdownlist dynamically. Last listItem of dropdownlist has TextField "Null value" and ValueField "0". But when I choose this item in DetailsView and try to send form, FormatException is thrown.
There is one strange moment. I complete dropdownlist dynamically in js-function after using web service. There is code.
//Variable 'result' is result of web service. Result is array of items.
//Every item has string-field 'Name' and int-field 'Kind_id'.
function Kind_success(result){
var ddl_select = document.getElementById("ddl_kinds");
ddl_select.innerHTML = "";
for (var n = 0; n < result.length; n++){
var option = document.createElement("option");
option.value = result[n].Kind_id;
option.innerHTML = result[n].Name;
ddl_select.appendChild(option);
}
// inserting null-item in dropdownlist
var null_option = document.createElement("option");
null_option.value = 0;
null_option.innerHTML = "Null value";
ddl_select.appendChild(null_option);
}
Web service returns result with two items. First has Kind_id 2, second has Kind_id 3. If I use any value for null_option, except 2 or 3, FormatException is thrown too. But it isn't trrown, if I use value 2 or 3 for null_option.Value.
Is there any way to correctly use null-option?