asp.net 中继器中的服务器控件
看来我在这里碰壁了。 我希望将一些数据源绑定到 asp.net 中继器(好吧,不一定是中继器,但看起来这就是我想要的)。 现在,问题是:我还需要中继器内的一些服务器控件来更新数据(文本框和按钮)。
据我了解,这真的不可能有条不紊地进行吗? 我不能只将文本框添加到项目模板中,然后稍后在代码隐藏中获取它。 至少不容易。 是否有任何已知的技术可以解决此类问题?
我无法使用网格视图,因为数据需要以某种方式格式化。
Seems like I've ran into a wall here. I want some datasource to be bound to an asp.net repeater (well, doesn't have to be a repeater, but it seems like that's what I want). Now, here's the catch: I also need some server-controls inside that repeater for updating the data (TextBox'es and buttons).
To my understanding, this aint really possible to do in an orderly manner? I can't just add a textbox to the itemtemplate, and then fetch it later on in the code-behind it seems. At least not easily. Are there any known techniques for this kind of problem?
I can't use a gridview, since the data needs to be formatted in a certain way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想使用 ItemCommand 并且只想循环遍历 Repeater 的项目集合,那么页面底部有一个“保存”按钮,您可以这样做:
当然,您需要确保 ASPX 中的 TextBox1 具有 Runat="Server" 属性。
If you don't want to use an ItemCommand and want to just loop through the Repeater's items collection, so you have one "save" button at the bottom of the page, you can do it like this:
Of course, you'll need to make sure that the TextBox1 in the ASPX has the Runat="Server" attribute.
您可以使用 Repeater.ItemDataBound 事件 定位嵌套在 Repeater 中的控件。
然后在后面的代码中:
You can use the Repeater.ItemDataBound Event to locate controls nested in a Repeater.
Then in code behind:
看来我的问题出在我的思考方式上:)
我的解决方案:
我只是像平常一样添加了控件,但在 ItemTemplate 中。 在控件的回调事件上,我会选择:(
按钮示例)
..等等。
因此,在找到 RepeaterItem 之后,我只是像处理任何 ControlGroup 一样对待它。 我实际上有 5 个不同的 textbosses,用 ID="txtName" 编码,但这并不重要,因为 asp.net 会自动在客户端标记中为控件提供“混淆”名称,并在回发时将其转换回我的 ID。
希望这对某人有帮助,抱歉打扰:)
Seems like my problem was in the way I was thinking :)
My solution:
I just added controls as I normally would do, but inside the ItemTemplate. On callback events of the controls, I'd go for:
(Button example)
.. etc..
So, after finding the RepeaterItem i just treat it as I would with any ControlGroup. Doesn't matter that I actually got 5 different textbosses, coded with ID="txtName", since asp.net automagically gives the controls "obfuscated" names in the client markup, and translates this back to my ID's on postback.
Hope this helps someone, and sorry for bothering :)