如何随机访问中继器的物品
我有一个带有 ItemTemplate
的转发器,其中包含一个 CheckBox
、TextBox
我的转发器代表一个检查列表以及一个 TextBox
对我从列表中选择的每个项目发表评论。
现在,我有一个用于编辑数据库中现有购物车的页面,它使用此转发器使用户能够更新他的列表。因此,我需要使用之前从数据库中选择的值来更新列表。我想不出一个简单的逻辑或方法来仅访问前一个列表中的转发器的项目...我正在考虑尝试仅访问数据库中的每个项目,而不是循环再循环。
我知道这真的很令人困惑,所以我将以更说明性的方式来说明:
数据库视图
Items
=======================
ID Name
--- -----
1 Banana
2 Apple
3 Strawberry
4 Orange
ShopCart_Items
========================================
ItemID ItemName CartID Value
------- --------- ------- ------
2 Apple 1 1
4 Orange 1 2
2 Apple 2 2
页面视图 首先,中继器填充了“项目”表中的所有项目,并且没有选中任何框或任何内容。
然后我选择一个特定的购物车(比如 cartId = 1)进行编辑,这就是我真正困惑的做法: 现在中继器将有大约 15-20 个项目,所以我需要访问用户在当前购物车 (cartId = 1) 上选择的用户想要编辑的项目,这样他就可以知道他选择了什么并开始选择新值,选中/取消选中复选框等。
我很抱歉提出这么长的问题,但我真的很困惑我应该/可以直接访问每个项目还是您建议我使用什么逻辑? ..谢谢=)
I have a repeater with an ItemTemplate
contains a CheckBox
, TextBox
My repeater represents a check list plus a TextBox
to put a comment to each item I select from the list.
Now, I've a page for editing an existing shopping cart in my database and it uses this repeater to enable the user to update his list. So I need to update the List with the previous selected values from the database. I can't think of a simple logic or way to access only the repeater's items that are on the previous list ...I'm thinking about trying to access each item that's in my database only instead of looping and looping.
I know It's really confusing so I'll just put it in a more illustrative way:
Database View
Items
=======================
ID Name
--- -----
1 Banana
2 Apple
3 Strawberry
4 Orange
ShopCart_Items
========================================
ItemID ItemName CartID Value
------- --------- ------- ------
2 Apple 1 1
4 Orange 1 2
2 Apple 2 2
PageView
First the repeater is populated with all the items that I have in my 'Items' table and no boxes check or anything.
Then I choose a specific cart (say cartId = 1) to edit, and here's what I'm really confused on how to do:
Now the repeater will have like 15-20 items, so I need to access just the items that the user choose on the current cart (cartId = 1) that the user want to edit, so he could know what did he choose and start choose new values, check/uncheck CheckBoxes, etc.
I'm sorry for all this long question, but I'm really confused should/can I access each item directly or what logic do you advice me to use ? ..Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您在一个中继器中混合了两个不同的实体 - 订单和订单项目。
在我看来,更好的方法是在页面上放置两个中继器:第一个用于显示订单,第二个用于显示所选订单的订单项目。这样,您可以对两个中继器使用简单的 SqlDataSource 控件,并将 ControlParameter 添加到用于根据第一个中继器中当前订单选择检索订单项的数据源。
I believe that you have mix two different entities in a one repeater - an orders and order items.
In my opinion the better approach is to place two repeaters onto the page: the first one for displaying orders and the second one for displaying order items for the selected order. This way you may use simple SqlDataSource controls for both repeaters and add a ControlParameter to the datasource used for retrieving order items depending on current order selection in the first repeater.