使用表单视图插入
我有一个表单视图。使用 formview 的数据源,我想将记录插入数据库,但我想插入从我在代码中创建的方法获得的值。这是否意味着我将无法使用向导直接将其编码到数据源上?
I have a formview. With the datasource of the formview i want to insert a record into the database, but i want to insert a value i get from a method i create in code. Doesn't that mean that i will not be able to directly code this onto the Data source using the wizard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能直接从方法中获取值,但您可以从以下位置获取动态值:
(有关详细信息,请参见此处 ==> http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx)
你可以把将方法的结果放入其中之一(例如,隐藏表单字段或会话),并仍然使用数据源向导来设置这一切。
如果这对您不起作用,则可以很容易地通过 FormView 控件的 ItemInserting 事件。
I don't think you can get the value directly from the method, but you can get dynamic values from:
(See here for details ==> http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx)
You could put the result of your method into one of these (i.e. hidden form field or Session for example) and still use the DataSource wizard to set it all up.
If this doesn't work for you, it's fairly easy to inject dynamic values into your inserts via the ItemInserting event of the FormView control.
我将使用带有 controlid=__PAGE 的控制参数并创建一个运行代码的属性,我不得不多次这样做。
i would use a control paramater with controlid=__PAGE and create a property that runs the code, i have had to do this numerous times.