我在insert.aspx中有以下代码行。
Source Code:
<asp:CheckBox ID="chkIncludeSignature" runat="server" Text="Include Signature" />
Code Behind:
command1.Parameters.AddWithValue("?IncludeSignature", chkIncludeSignature.Checked ? 1 : 0);
这是update.aspx的代码:
Source Code:
<asp:CheckBox ID="chkIncludeSignature" runat="server" Text="Include Signature" />
Code Behind:
chkIncludeSignature.Checked=dtInvoice.Rows[0]["IncludeSignature"].ToString();
我在db表中插入了复选框值。我希望在插入表单中插入的更新表单中的选定值。我收到错误为“无法将类型字符串转换为bool”。
答案 0 :(得分:1)
chkIncludeSignature.Checked=dtInvoice.Rows[0]["IncludeSignature"] == 1 ? true : false;
答案 1 :(得分:0)
删除最后一行代码末尾的.ToString()
。如果数据库中IncludeSignature
为bit
数据类型,则dtInvoice.Rows[0]["IncludeSignature"]
必须返回bool
值。您也可以使用bool.TryParse(dtInvoice.Rows[0]["IncludeSignature"].ToString(), out boolVariable);
。
答案 2 :(得分:0)
我刚刚更新了这一行...并且工作正常......:)
chkIncludeSignature.Checked= Convert.ToBoolean(dtInvoice.Rows[0]["IncludeSignature"]);