C# 更改asp.net中dropdownlist的值
我在ASP.NET web表单中有一个下拉列表,但我无法更改该下拉列表的值 我的下拉列表:C# 更改asp.net中dropdownlist的值,c#,asp.net,C#,Asp.net,我在ASP.NET web表单中有一个下拉列表,但我无法更改该下拉列表的值 我的下拉列表: <asp:DropDownList ID="dropeditdeactive" runat="server"> <asp:ListItem Value="false">Active</asp:ListItem> <asp:ListItem Value="true">Deactive</asp:ListItem> </asp:
<asp:DropDownList ID="dropeditdeactive" runat="server">
<asp:ListItem Value="false">Active</asp:ListItem>
<asp:ListItem Value="true">Deactive</asp:ListItem>
</asp:DropDownList>
当我在cm.Connection.Close()上设置断点时
并读取(dr[“URL”]).ToString()的数据代码>在即时窗口中,我收到以下错误:
System.Data.dll中发生类型为“System.InvalidOperationException”的未处理异常
其他信息:当不存在数据时,尝试读取无效
即使我不能用此代码设置值
:
dropeditdeactive.SelectedValue = "false";
或者使用Convert.ToBoolean
检查读卡器是否有数据。即:
if(dr.HasRows)
{
// code goes here
}
在读取值之前检查dr.HasRows的值。这是真是假。另外,您是否确定存储过程正在返回一个标记为“URL”的列?dr[“URL”]的结果是什么?这是真/假还是什么?@macoms01是它的结果true@NiMa数据库中的ist boolan在您读取代码中的URL之前(执行此行之前):droEditDeactive.SelectedValue=(dr[“URL”]).ToString()的值是多少
if(dr.HasRows)
{
// code goes here
}