asp.net - Binding RadioButtonList to nullable varchar workaround? (SelectedValue which is invalid because it does not exist...) -
In my database I have a blank varchar column in the table.
I am compelling a gridview through this table ObjectDatasource and TemplateField similar to this:
& amp; Asp: radio button list id = "rblRequirementOption" duplication = direction = "horizontal" runat = "server" repeat = "flow" selected value = '& lt;% # binding ("RequirementOption")% & gt; '& Gt; & Lt; Asp: ListItem value = "" text = "style =" display: none "/> & Lt; Asp: ListItem value = "requirement" text = "requirement" & gt; & Lt; / Asp: ListItem & gt; & Lt; Asp: ListItem value = "do not use" text = "do not use" & gt; & Lt; / Asp: ListItem & gt; & Lt; / ASP: RadioButtonList & gt;
If there are any empty values in that column in the table, I get an error:
"rblRequirementOption 'has a SelectedValue that is invalid because it is not present in the list of parameters Name: value "
So as you can see, I have tried to add a placeholder radio button to adjust the empty values, which is the commonly recommended method to handle . This error, but in this situation, it seems that "DBNull.Value" is not considered equal.
Certainly no need to change the tap of zero before I force it.
UPDATE
Actually, it is The right syntax to do this (I was going around with a default value option and all got mixed.)
You shoud use:
and ATP: Radiobutton list runat = server id = "RD" selectedValue = '& lt;% # bind ("sex"). GetType () == Typef (debugl)? Zero: Dam ("Gender")% & gt; '& Lt; Asp: ListItem text = "male" value = "1" & gt; & Lt; / Asp: ListItem & gt; & Lt; Asp: ListItem text = "female" value = "2" & gt; & Lt; / Asp: ListItem & gt; & Lt; / ASP: RadioButtonList & gt;
Comments
Post a Comment