我正在为一个学校项目做这个网站,当我运行这个网站时,我有一个GridView,我在其中选择一个注册表,然后它打开FormView,其中包含有关所选注册表的所有详细信息
网站运行的图片
现在,当我在FormView上点击"编辑"时,会出现以下错误:'ddl_SelectMe'的SelectedValue无效,因为它不在项目列表中。参数名称:值
我知道,出现这个错误是因为字段"Mãe"上的值为null,但我看到了数据库,该值可能为null。(相同错误适用于"Pai"one_answers"Comprador"字段)
这里是发生错误的代码部分,如果需要,我可以将所有代码放入
<asp:FormView ID="fv_Alteracoes" runat="server" DataKeyNames="idCao" DataSourceID="SqlDS_InsEdiDel">
<EditItemTemplate>
<table>
<tr>
<td>Mãe:</td>
<td>
<asp:DropDownList ID="dll_SelectMae" runat="server" DataSourceID="SqlDS_ListarMae" DataTextField="idCao" DataValueField="idCao"
SelectedValue='<%# Bind("Mae") %>'>
</asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDS_ListarMae" ConnectionString='<%$ ConnectionStrings:ConnectionString %>'
SelectCommand="SELECT [idCao], [Nome] FROM [tbl_Cao] WHERE ([Sexo] = 'F')">
</asp:SqlDataSource>
</td>
</table>
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" />
<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
如果我也这样做,但有一个注册表,所有的细节都填写了,网站工作100%,因为我想要
完美运行的网站图片
有人能帮我如何停止这个错误并保留DropDownList来编辑字段吗?
PS:对不起我的英语,但我是葡萄牙人,谢谢你的帮助
更改数据源,使null可以被允许为:
SELECT [idCao], [Nome] FROM [tbl_Cao] WHERE ([Sexo] = 'F')
union
Select null,'None'