Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改asp.net中dropdownlist的值_C#_Asp.net - Fatal编程技术网

C# 更改asp.net中dropdownlist的值

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.NET web表单中有一个下拉列表,但我无法更改该下拉列表的值 我的下拉列表:

<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
}