2017-03-01 76 views
-2

在布尔值中,您可以传递2个值,true或false,但m试图从下拉列表中传递第3个值(空值),approved= true(1), rejected=false(0), pending= (NULL)能够通过空值从c下的布尔值形式的下拉列表中传递一个空值到数据库#

<td> 
    <asp:DropDownList ID="DropDownList3" runat="server" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged"> 
     <asp:ListItem Value="DBNull">Pending For Approval</asp:ListItem> 
     <asp:ListItem Value="1">Approve</asp:ListItem> 
     <asp:ListItem Value="0">Reject</asp:ListItem> 
    </asp:DropDownList> 
</td> 

否则,如果(e.CommandName == “批准”) {是显示..failed

  bool? Status = null; 
      string Request_ID = ((Label)e.Item.FindControl("Label1")).Text; 
      string Employee_ID = ((Label)e.Item.FindControl("Label2")).Text; 
      string Certification_Name = ((Label)e.Item.FindControl("Label3")).Text; 
      string Issue_Date = ((Label)e.Item.FindControl("Label4")).Text; 
      string Valid_Till_Date = ((Label)e.Item.FindControl("Label5")).Text; 
      string Status = ((DropDownList)e.Item.FindControl("DropDownList3")).SelectedItem.Value; 
      string Requested_On = ((Label)e.Item.FindControl("Label6")).Text; 
      string Approved_By = ((Label)e.Item.FindControl("Label8")).Text; 
      string Approved_On = ((Label)e.Item.FindControl("Label9")).Text; 
      SqlCommand cmd = new SqlCommand("update Request_For_External_Certification set Status='" + Status + "' where Request_ID=" + Request_ID, con); 
      con.Open(); 
      cmd.ExecuteNonQuery(); 
      con.Close(); 

      FillData(); 

误差为空值转换为试图转换位 价值也,但没有运气

string status = Convert.ToBoolean(DropDownList2.SelectedItem.Value) 

回答

1

您使用的是正常bool只能有真正值。您需要在这里使用nullable布尔。你可以这样说:

bool? status = null; 

Nullable<bool> status = null; 

希望它能帮助!

+0

yes,但是这些值需要通过html页面,而不是C#,在c#中,只会调用与sqserver连接的值 – zee21

+0

哦,没有注意到你更新了你的问题描述。 – mindOfAi

+0

你能告诉我们你得到错误的代码块吗? – mindOfAi

相关问题