没有 FormView 的数据绑定?
我有一个 ASP.NET 页面,其中包含一个 Wizard 控件,其中包含多个步骤和大约 80 个表单字段。数据从代码隐藏页面收集并插入到数据库中。我需要设置此表单,以便您不仅可以插入,还可以编辑记录。所以我想对字段进行数据绑定。我不想使用 FormView,因为那样我就必须修改现有代码,因为您无法直接访问 FormView 内的控件。有没有一种方法可以在不使用 FormView 的情况下对字段进行数据绑定?顺便说一句,我对此很陌生,如果答案很明显,我很抱歉。
I have an ASP.NET page with a Wizard control containing several steps and about 80 form fields. The data is collected and inserted to a database from the code behind page. I need to set this form up so you can not only insert, but edit a record as well. So I want to databind the fields. I'd rather not use a FormView because then I would have to revise my existing code, since you can't access controls inside a FormView directly. Is there a way to databind the fields without using a FormView? I'm new at this by the way so sorry if the answer should be obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向导只是一个包含许多步骤的 UI 控件。您可以使用它来插入、编辑、删除或任何您能想到的操作。您可以有一个插入向导和一个编辑向导。区别在于,它们有两个,并且每个背后的代码(大概在 CompletedStep 上)将具有稍微不同的代码来保存数据。插入向导将调用插入数据库查询,编辑向导将调用更新查询。
话虽这么说,您可以访问
FormView
内的控件,我不确定您为什么说不能访问独立于FormView的控件。你可以。请参阅使用 FindControl:访问表单视图中的控件。您甚至可以将两个向导放入表单视图的两种状态中 -
InsertTemplate
和EditTemplate
但这有点疯狂:)A wizard is just a UI control with many steps in it. You can use it to insert, edit, delete or anything else you can think of. You can have an INSERT wizard and an EDIT wizard. The difference would be that there would be two of them and that the code behind for each one (presumably on the CompletedStep) would have slightly different code to persist the data. The insert wizard would call an insert database query and the edit one would call an update query.
That being said, you can access the control inside a
FormView
, I'm not sure why you said that you can't access controls indie a FormView. You can. See Using FindControl: Accessing Controls in a Formview.You could even put the two wizards inside the two states of the formview -
InsertTemplate
andEditTemplate
but thats getting a little crazy :)