使用FormView插入
我有一个 formview 控件,在 ItemCreated
事件中,我用默认值“启动”一些字段。
但是,当我尝试使用 formview 进行插入时,在调用 ItemInserting
事件之前,由于某种原因它首先调用 ItemCreated
。这会导致在插入发生之前字段被默认值覆盖。
如何让它在 ItemInserting
事件之前不调用 ItemCreated
事件?
I have a formview control, and on the ItemCreated
event, I am "priming" some of the fields with default values.
However, when I try to use the formview to insert, before the ItemInserting
event gets called, for some reason it calls ItemCreated
first. That results in the fields being over-written with the default values right before the insert happens.
How do I get it to not call the ItemCreated
event before the ItemInserting
event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 formview Databound 事件而不是 formview ItemCreated 事件来设置值,尝试像
也检查类似问题的这个线程
FormView_Load 被覆盖 C# ASP.NET
you need to use formview Databound event instead of formview ItemCreated event to set values, try like
Also check this thread of similare issue
FormView_Load being overwritten C# ASP.NET
您无法更改事件触发的顺序。但是,您可能应该将设置默认值的代码包装在
!IsPostBack
中,这样它就不会重置您的值,例如:You cannot change the order in which the events fire. However, you should probably wrap the code that sets the default values inside
!IsPostBack
so that it doesn't reset your values for example:尝试检查 CurrentMode 属性。
Try checking the CurrentMode property of the form view.