C#:RadioButtonList中的DataBase Null

问题描述:

我想有一个radiobuttollist你可以选择值null。C#:RadioButtonList中的DataBase Null

事情是这样的:

<asp:RadioButtonList ID="rblCD" runat="server" SelectedValue='<%# Bind("tblCD") %>'> 
      <asp:ListItem Value="RW">RW</asp:ListItem> 
      <asp:ListItem Value="R">R</asp:ListItem> 
      <asp:ListItem Value="DBNull">None</asp:ListItem> 
</asp:RadioButtonList> 

非常感谢, 文森特

在RadioButtonList的值总是字符串。你将不得不做这样的事情

<asp:ListItem Value="">None</asp:ListItem> 

然后,当你阅读从控制数据做一些像

if (rblCD.SelectedValue == string.Empty) 
{ 
    MyDataRow["Column"] = DBNull.Value; 
} 

是你可以做的,在你的榜样

if(rblCD.SelectedValue== "DBNull") 
{ 
    DataRow["Column"] = DbNull.Value; 
} 

哟应该使用:

<asp:RadioButtonList runat=server ID="rd" 
SelectedValue='<%# Eval("myField").GetType() == typeof(DBNull) ? null : Eval("myField") %>'> 
      <asp:ListItem Text="yes" Value="1"></asp:ListItem> 
      <asp:ListItem Text="no" Value="2"></asp:ListItem> 
</asp:RadioButtonList>