gpt4 book ai didi

ASP.NET 表单查看更新时的 IF

转载 作者:行者123 更新时间:2023-12-02 19:08:22 26 4
gpt4 key购买 nike

我想在更新表单 View 之前运行 if;如果是,那么...“消息”并取消更新查询如果没有继续更新查询。

我已经尝试过这个,但我在 if 的第一行收到“对象实例未设置为空实例......”?并且该项目无论如何都会更新

Private Sub FormView2_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView2.ItemUpdating
Dim status As TextBox = FormView1.FindControl("ApprovalStatusTextBox")


If status.Text = "approved" Or "denied" Then
e.Cancel = True
lblupdaterequest.Text = "you cannot update this request as it has already been responded to"
Else
HolidayDetailsdatasource.Update()
End If

有人知道实现这样的事情更好吗?

确切错误:

   System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=WebApplication1
StackTrace:
at WebApplication1.HolidayApprovalDetails.DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e) in line 32
at System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArgs e)
at System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation)
at System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
at System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

最佳答案

我至少可以看到您正在从“FormView1”检索状态 TextBox 的值,而您的子 ItemUpdating 引用“FormView2”。

更改此设置后,尝试在 if 之前添加一个消息框,以确保您获得所需的正确值:

MsgBox(status.Text)

希望它能帮助您解决问题。

关于ASP.NET 表单查看更新时的 IF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10001368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com