我收到以下错误:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
代码:
<asp:RadioButtonList ID="rbtVerified" runat="server" Visible='<%#!(bool)Eval("ReadOnly") %>' >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
正在从数据库中成功检索到值ReadOnly
,它是bool
(在sql server中保存为位。问题到底是什么?
尝试绑定数据时也会抛出异常(注意:bool test
只是一个测试,用于检查是否正确地从数据库中检索变量ReadOnly
。
DataTable dt = new LeaveLogic().GetManagerUnverifiedLeaveRequests(Convert.ToInt32(Context.User.Identity.Name));
if (dt.Rows.Count > 0)
{
bool test = Convert.ToBoolean(dt.Rows[0]["ReadOnly"]);
RptLeaveRequests.DataSource = dt;
RptLeaveRequests.DataBind();
}
更多的拘留错误:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Specified cast is not valid.
Source=App_Web_kdnthep4
StackTrace:
at ASP.webpages_verifyleaverequests_aspx.__DataBinding__control43(Object sender, EventArgs e) in c:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx:line 35
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.BindData() in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 58
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.Page_Load(Object sender, EventArgs e) in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 24
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: