- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个连接到 LinqDataSource 的 FormView,我想按查询字符串对其进行过滤。基本上,如果通过查询字符串传入 ID,我只想显示该记录,否则如果没有提供 ID,则只显示所有记录。我已经设法使用几种不同的方法让它工作,但是每次我尝试将数据保存在 FormView 中时,我都会遇到异常:Operator '==' incompatible with operand types 'Int32?'和“对象”
。
当我调用 FormView.UpdateItem(true)
时出现上述异常。下面是我如何过滤 LinqDataSource:
protected void ldsIncidents_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
if (!String.IsNullOrEmpty(Request.QueryString["id"]))
{
e.Result = db.Incidents.Where(i => i.Incident_Number == Convert.ToInt32(Request.QueryString["id"]));
}
}
当我调用 FormView.UpdateItem(true)
时抛出异常。从上面的 Selecting
事件中删除代码后,一切正常,但我无法再过滤数据。我也尝试过将 WhereParameters 动态添加到 LinqDataSource,但同样的事情发生了。有谁知道为什么会这样或如何解决?如果有帮助,这是我的堆栈跟踪:
Exception Type: System.Web.Query.Dynamic.ParseException
Message: Operator '==' incompatible with operand types 'Int32?' and 'Object'
Stack Trace:
at System.Web.Query.Dynamic.ExpressionParser.CheckAndPromoteOperands(Type signatures, String opName, Expression& left, Expression& right, Int32 errorPos)
at System.Web.Query.Dynamic.ExpressionParser.ParseComparison()
at System.Web.Query.Dynamic.ExpressionParser.ParseLogicalAnd()
at System.Web.Query.Dynamic.ExpressionParser.ParseLogicalOr()
at System.Web.Query.Dynamic.ExpressionParser.ParseExpression()
at System.Web.Query.Dynamic.ExpressionParser.Parse(Type resultType)
at System.Web.Query.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
at System.Web.Query.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values)
at System.Web.Query.Dynamic.DynamicQueryable.Where(IQueryable source, String predicate, Object[] values)
at System.Web.UI.WebControls.DynamicQueryableWrapper.Where(IQueryable source, String predicate, Object[] values)
at System.Web.UI.WebControls.QueryableDataSourceView.ExecuteQueryExpressions(IQueryable source, QueryContext context)
at System.Web.UI.WebControls.QueryableDataSourceView.ExecuteQuery(IQueryable source, QueryContext context)
at System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.WebControls.CompositeDataBoundControl.get_Controls()
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.DataBoundControlHelper.ExtractValuesFromBindableControls(IOrderedDictionary dictionary, Control container)
at System.Web.UI.WebControls.FormView.ExtractRowValues(IOrderedDictionary fieldValues, Boolean includeKeys)
at System.Web.UI.WebControls.FormView.HandleUpdate(String commandArg, Boolean causesValidation)
at System.Web.UI.WebControls.FormView.UpdateItem(Boolean causesValidation)
at PRIDE.Pages.Incidents.View.btnSaveIncident_Click(Object sender, EventArgs e) in C:\Users\hopfnejo\Documents\Development Projects\PRIDE\PRIDE\Pages\Incidents\View.aspx.cs:line 317
编辑
下面是 FormView 的 ItemUpdating
事件的内容:
protected void fvIncident_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
TabContainer tc = fvIncident.FindControl("tcMain") as TabContainer;
e.NewValues["Division"] = (tc.Tabs[0].FindControl("cboDivision") as DropDownList).SelectedValue;
e.NewValues["Safety"] = (tc.Tabs[0].FindControl("chkSafety") as CheckBox).Checked;
e.NewValues["Quality"] = (tc.Tabs[0].FindControl("chkQuality") as CheckBox).Checked;
e.NewValues["Cost"] = (tc.Tabs[0].FindControl("chkCost") as CheckBox).Checked;
e.NewValues["Production"] = (tc.Tabs[0].FindControl("chkProduction") as CheckBox).Checked;
e.NewValues["Environment"] = (tc.Tabs[0].FindControl("chkEnvironment") as CheckBox).Checked;
e.NewValues["Department"] = (tc.Tabs[0].FindControl("cboDepartment") as DropDownList).SelectedValue;
e.NewValues["Area"] = (tc.Tabs[0].FindControl("cboArea") as DropDownList).SelectedValue;
e.NewValues["Initiated_By"] = (tc.Tabs[0].FindControl("txtInitiatedBy") as TextBox).Text;
e.NewValues["KRA_Notes"] = (tc.Tabs[0].FindControl("txtKRANotes") as TextBox).Text;
e.NewValues["Incident_type"] = (tc.Tabs[0].FindControl("cboIncidentType") as DropDownList).SelectedValue;
e.NewValues["Aspect_Affected"] = (tc.Tabs[0].FindControl("cboAspectAffected") as DropDownList).SelectedValue;
e.NewValues["Incident_Level"] = (tc.Tabs[1].FindControl("cboIncidentLevel") as DropDownList).SelectedValue;
e.NewValues["ADM_Testing_Within_Guidelines"] = (tc.Tabs[1].FindControl("chkADMTestingWithinGuidelines") as CheckBox).Checked;
e.NewValues["ADM_Testing_Required"] = (tc.Tabs[1].FindControl("chkADMTestingRequired") as CheckBox).Checked;
e.NewValues["Number_Of_People_Involved"] = (tc.Tabs[1].FindControl("txtNumPeopleInvolved") as TextBox).Text;
e.NewValues["Mill_State"] = (tc.Tabs[2].FindControl("cboMillState") as DropDownList).SelectedValue;
e.NewValues["Area_Downtime"] = (tc.Tabs[2].FindControl("txtDowntime") as TextBox).Text;
e.NewValues["Production_Amount_Lost"] = (tc.Tabs[2].FindControl("txtProductionAmountLost") as TextBox).Text;
e.NewValues["Production_Actual_or_Estimate"] = (tc.Tabs[2].FindControl("cboProductionActualOrEstimate") as DropDownList).SelectedValue;
e.NewValues["Production_Units"] = (tc.Tabs[2].FindControl("cboProductionUnits") as DropDownList).SelectedValue;
e.NewValues["Environmental_Impact"] = (tc.Tabs[3].FindControl("txtEnvironmentalImpact") as TextBox).Text;
e.NewValues["Environmental_Specialist_Notified"] = (tc.Tabs[3].FindControl("cboEnvironmentalSpecialistNotified") as DropDownList).SelectedValue;
e.NewValues["Environmental_Incident_Reportable_to_Government"] = (tc.Tabs[3].FindControl("cboEnvironmentalIncidentReportableToGovernment") as DropDownList).SelectedValue;
e.NewValues["Environmental_Governement_Agency_Involved"] = (tc.Tabs[3].FindControl("txtGovernmentAgencyInvolved") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[3].FindControl("txtDateReported") as TextBox).Text))
e.NewValues["Environmental_Date_Reported"] = null;
else
e.NewValues["Environmental_Date_Reported"] = (tc.Tabs[3].FindControl("txtDateReported") as TextBox).Text;
e.NewValues["Environmental_Action_Taken"] = (tc.Tabs[3].FindControl("txtEnforcementActionTaken") as TextBox).Text;
e.NewValues["Environmental_Reference_Number"] = (tc.Tabs[3].FindControl("txtReferenceNumber") as TextBox).Text;
e.NewValues["Procedures"] = (tc.Tabs[4].FindControl("txtProceduresAffected") as TextBox).Text;
e.NewValues["Referances"] = (tc.Tabs[4].FindControl("txtReferences") as TextBox).Text;
e.NewValues["Reviewed_By__BUL_"] = (tc.Tabs[8].FindControl("txtReviewedByBUL") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtSignOffDateBUL") as TextBox).Text))
e.NewValues["Sign_Off_Date__BUL_"] = null;
else
e.NewValues["Sign_Off_Date__BUL_"] = (tc.Tabs[8].FindControl("txtSignOffDateBUL") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtPlannedReviewDate") as TextBox).Text))
e.NewValues["Planned_Review_Date"] = null;
else
e.NewValues["Planned_Review_Date"] = (tc.Tabs[8].FindControl("txtPlannedReviewDate") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtPlannedCompletionDate") as TextBox).Text))
e.NewValues["Planned_Completion_Date"] = null;
else
e.NewValues["Planned_Completion_Date"] = (tc.Tabs[8].FindControl("txtPlannedCompletionDate") as TextBox).Text;
e.NewValues["Signed_Off_By__BGL_"] = (tc.Tabs[8].FindControl("txtSignedOffByBGL") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtSignOffDateBGL") as TextBox).Text))
e.NewValues["Sign_Off_Date__BGL_"] = null;
else
e.NewValues["Sign_Off_Date__BGL_"] = (tc.Tabs[8].FindControl("txtSignOffDateBGL") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtActualReviewDate") as TextBox).Text))
e.NewValues["Actual_Review_Date"] = null;
else
e.NewValues["Actual_Review_Date"] = (tc.Tabs[8].FindControl("txtActualReviewDate") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtActualCompletionDate") as TextBox).Text))
e.NewValues["Actual_Completion_Date"] = null;
else
e.NewValues["Actual_Completion_Date"] = (tc.Tabs[8].FindControl("txtActualCompletionDate") as TextBox).Text;
e.NewValues["Signed_Off_By__Mill_Manager_"] = (tc.Tabs[8].FindControl("txtSignedOffByMillManager") as TextBox).Text;
if (String.IsNullOrEmpty((tc.Tabs[8].FindControl("txtSignOffDateMillManager") as TextBox).Text))
e.NewValues["Sign_Off_Date__Mill_Manager_"] = null;
else
e.NewValues["Sign_Off_Date__Mill_Manager_"] = (tc.Tabs[8].FindControl("txtSignOffDateMillManager") as TextBox).Text;
}
编辑 2
我已经尝试在我拥有与 LinqDataSource 和 FormView 相关的处理程序的唯一事件中设置断点,并且在异常发生之前没有触发任何事件。事件是:
LinqDataSource_Selecting
FormView_ItemUpdating
FormView_DataBound
单击“保存”按钮后,我的所有断点都没有到达。这里炸了,用处不大:
这是我的 FormView 声明:
<asp:FormView ID="fvIncident" runat="server" DefaultMode="Edit"
DataSourceID="ldsIncidents" DataKeyNames="Incident_Number"
AllowPaging="True" CssClass="full" ondatabound="fvIncident_DataBound"
onitemupdating="fvIncident_ItemUpdating">
还有我的 LinqDataSource 声明:
<asp:LinqDataSource ID="ldsIncidents" runat="server"
ContextTypeName="PRIDE.PRIDEDataContext" EnableUpdate="True" EntityTypeName=""
TableName="Incidents" OrderBy="Incident_Number DESC"
onselecting="ldsIncidents_Selecting">
</asp:LinqDataSource>
最佳答案
试试这个。
IQueryable<Incident> query = this.context.Incidents;
string whereCaluse = String.Format("Incident_Value=={0}",Request.QueryString["id"]);
query.Where(whereClause);
e.Result=query;
关于c# - 按查询字符串过滤 FormView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15348204/
我有一个像这样的 FormView: Test Name '> Test Name 这意味着在 InsertMode 中,用户可以使用下拉列表更改 Suite
插入记录后我有一个表单 View 我想知道插入记录的最后一个 id 最佳答案 你必须依赖你的数据源对象。 例如,如果您使用的是 EntityDataSource,则非常简单。 1 catch 事件 E
定义 FormView 派生类时: class PrefsView(FormView): template_name = "prefs.html" form_class = MyFor
我有一个连接到 LinqDataSource 的 FormView,我想按查询字符串对其进行过滤。基本上,如果通过查询字符串传入 ID,我只想显示该记录,否则如果没有提供 ID,则只显示所有记录。我已
我想使用表单 View 显示学生成绩单。如果是第二学期的成绩单,成绩单将有额外的栏目,如果是第三学期的成绩单,则将有另外两栏。要找出它是哪个术语,我需要评估 TermNumber 属性,并显示适当的标
我一整天都在想办法解决这个问题 - 我有一个 FormView带有一些文本字段和 GridView有几列。出于某种原因,我的 FormView不显示,但 GridView 我的 .aspx 文件如下:
我有一个包含窗体 View 和 ObjectDataSource 的 ASP.NET 页面。在页面上,我只有 4 个字段绑定(bind)到我的数据源中的字段。我的数据源包含 10 个字段。当我调用更新
Django FormView 和 CreateView 有什么区别? 我看到的唯一区别是,FormView 需要 ModelForm 但 CreateView 不需要。 否则,两者都会做同样的事情来
我已经做到了,任何使用用户名注册的用户都会自动将其用户名转换为小写。 user/forms.py 我现在遇到一个问题,我无法找到一种方法将登录表单中的用户名在提交时转换为较低的用户名。因为我仍然希望用
我的 Form 中遇到了一些奇怪的故障执行。我不确定这是一些实现错误还是 SwiftUI 本身的错误。 所以基本上我想做的是典型的“ToDo/TimeTracking”应用程序。我想创建一个引用项目实
我有一个使用 FormView 的类 View 。我需要更改表单的名称,即在我的旧函数 View 中以前是这样的: upload_form = ContactUploadForm(request.u
有这个 urls.py 片段: url(r'^storageitem/(?P[\w]+)/addtransaction/$', login_required( StorageItemTrans
ID : CpuName :
我需要在插入新项目后进入编辑模式。 OnItemInserted 方法: protected void fvReport_ItemInserted(Object sender, FormViewIns
在 ItemUpdating 上,我能够检索字段值,但我不能只检索更新的值。 有没有比下面的方法更好的方法? protected void fwHotelDetails_ItemUpdating(Ob
如何从代码后面检查表单 View 是否为空?我试过 DataItemCount ==0 但它似乎不起作用。谢谢 if (FormView_imgBG.DataItemCount == 0)
我需要找到这个 标签位于 FormView 中控制,我需要根据条件删除这个标签,但我无法使用 FormView.FindControl 找到它方法
我通过谷歌搜索,发现很多人都在为这个问题苦苦挣扎,但我仍然没有找到正确的答案。 http://i.stack.imgur.com/15jen.png 我有一个表单 View ,需要检查语言代码是否重复
下面是我的代码。我遇到的问题是我的绑定(bind)文本字段没有按预期将信息发送回 UpdateCommand。如果我将任何 @variables 替换为硬编码文本,则更新会按预期进行。因此,如果我将
188 点 400 个帖子 带有下拉列表的动态 Formview 非常失败。 6 小时 21 分钟前|LINK 我脑子里有一个想法,我正在努力实现它,但它没有用。这是需要发生的事情:用户从列表中选择一
我是一名优秀的程序员,十分优秀!