带表的 Formview 控件,tr 中设置为 runat server 的控件不插入
这是一个奇怪的情况。在我的 FormView
控件中,我放置了一个 进行布局。在行 (
) 中,我添加了
ID
和 runat="server"
。插入只保存了一些数据,我认为这很奇怪。我查看了为什么这些字段被存储而其他字段没有,唯一的区别是我没有将 ID
或 runat="server"
添加到 <代码>s。移除“runat”后,插件即可正常工作。
我认为这与行的初始化方式与控件或 FormView 的初始化方式有关。有什么想法为什么会发生这种情况吗?目前,我正在从表行中删除 ID
。
Here's an odd situation. In my FormView
control, I put a <table>
for layout. With the rows (<tr>
) I added ID
s and runat="server"
. The insert only saved some of the data, which I thought was odd. I looked to see why those fields stored and others didn't, and the only difference was I hadn't added the ID
s or runat="server"
to the <tr>
s. Removing the "runat" allowed the insert to work normally.
I assume this has something to do with the way the rows are initialized versus when the control or FormView
is initialized. Any thoughts why this happens? For now, I'm removing the ID
s from the table rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的想法是正确的。
FormView
仅查看顶级控件。如果您将预期的输入控件之一嵌入到另一个服务器端控件中,则FormView
不会看到它(它已隐藏在外部控件内)。即使在代码隐藏中,您也必须使用FindControl
方法从服务器端获取输入标记因此,如果您有这个:
FormView
唯一看到的是顶级元素()。除非你这样做,否则你甚至不会在代码隐藏中看到
TextBox
,除非你这样做:所以我的建议是去掉 codebehind 中的“runat”和“ID”标签code> 元素;由于它们仅用于显示目的,因此您在服务器端并不真正需要它们。
我希望事情能澄清一点。
You're on the right track in your thinking.
The
FormView
only looks at top-level controls. If you embed one of your intended input controls inside of another server-side control, theFormView
doesn't see it (it's been hidden inside the outer control). Even in your code-behind you'd have to use theFindControl
method to get the input tag out of the server-side<tr>
Thus, if you had this:
The only thing the
FormView
sees is the top-level element (the<tr>
). You wouldn't even see theTextBox
in your codebehind unless you did this:So my suggestion would be to leave off the "runat" and "ID" tags from the
<tr>
elements; since they are just for display purposes, you don't really need them at the server-side.I hope that clears things up a little.